hdu 1212 数论

hdu 1212 数论
利用  (a*b)%m = (a%m)*(b%m)%m

# include < stdio.h >
# include
< math.h >
# include
< stdlib.h >
# include
< string .h >
# include
< ctype.h >
# include
< limits.h >
# include
< iostream >
# include
< algorithm >

using   namespace  std;
int  main()
{
    
char  str[ 1100 ];
    
long  a,t,i,len;
    
while (cin >> str >> a)
    {
        
for (len  =  strlen(str),i  =   1 ,t  =  str[ 0 -   ' 0 ' ;i  <  len; i  ++ )
        {
            t 
=  ( ( 10 % a) * (t % a) % +  (str[i] - ' 0 ' ) % a ) % a;
        }
        printf(
" %d\n " ,t);
    }
    
return   0 ;
}


你可能感兴趣的:(hdu 1212 数论)