心如止水
Je n'ai pas le temps
posts - 400,comments - 130,trackbacks - 0
题目大意:给出一个256进制数,在这个数字后面增加2位,使得可以被34943整除。
以下是我的代码:
#include <cstdio>
#include <cstring>
using namespace std;

typedef long long int64;

const int kMaxn = 1050;

int len;
int64 re, ans;
char s[kMaxn], output[7];

int main () {
#ifndef ONLINE_JUDGE
    freopen ( "data.in", "r", stdin );
#endif
    
    while ( gets ( s ) ) {
        len = strlen ( s );
        //printf ( "%d\n", len );
        if ( s[0] == '#' )
            break;
        
        re = 0;
        for ( int i = 0; i < len; i++ )
            re = ( re * 256 + s[i] ) % 34943;
        re = re * 256 * 256 % 34943;
        
        ans = ( re ? 34943 - re : 0 );
        
        //printf ( "%lld %lld\n", re, ans );
        
        sprintf ( output, "%04x\n", (int)ans );
        for ( int i = 0; i < 4; i++ )
            if ( output[i] >= 'a' && output[i] <= 'z' )
                output[i] = output[i] - 'a' + 'A';
        printf ( "%c%c %c%c\n", output[0], output[1], output[2], output[3] );
    }
    
    return 0;
}
posted on 2011-09-28 16:18 lee1r 阅读(690) 评论(0)  编辑 收藏 引用 所属分类: 题目分类:数学/数论

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理