码迷,mamicode.com
首页 > 其他好文 > 详细

大整数的求余运算

时间:2018-02-11 21:30:28      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:nbsp   clu   ascii   sci   test   数学计算   gpo   blog   系统   

在加密系统中,长长要求把一行字符看作是一串二进制位,然后对某个固定的数进行求余运算。

解答:

#include <stdio.h>                                                                                 
int main()
{
    const int K=34943;
    unsigned int L=0;
    unsigned char c;
    unsigned long long test=0b0011001100110100001110010011010000110011;  //34943的ascii码
    printf("%llu\n",test);   //勉强能够存下,用于验证计算是否准确。
    while(scanf("%c",&c) && c!=\n){     //这里输入字符串“34943”,和test相同
        L=((L<<8)+c)%K;      //左移8位的原因是c的长度是8个二进制位,可以参考求余的数学计算方法。
    }   
    test=test%34943;
    printf("L=%u\n",L);
    printf("test=%llu\n",test);
    return 0;
}

 

大整数的求余运算

标签:nbsp   clu   ascii   sci   test   数学计算   gpo   blog   系统   

原文地址:https://www.cnblogs.com/litifeng/p/8443081.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!