Hdu 1212 Big Number

同余定理的运用:

 (a+b)%c=(a%c+b%c)%c;

 (a*b)%c=(a%c*b%c)%c;

CODE:

#include <stdio.h>
#include <stdlib.h>
#include < string.h>

using  namespace std;

const  int maxn =  1001;
char s[maxn];



int main()
{
     int m;
     while(~scanf( " %s%d ", s, &m))
    {
         int l = strlen(s);
         int ans =  0;
         for( int i =  0 ; i < l ; i++)
        {
            ans = (ans* 10%m + (s[i]- ' 0 ')%m)%m;
        }
        printf( " %d\n ", ans);
    }
     return  0;

} 

你可能感兴趣的:(number)