题目大意:给出一个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 阅读(708)
评论(0) 编辑 收藏 引用 所属分类:
题目分类:数学/数论