标签:
int gcd(int a, int b)
{
return b == 0 ? a : gcd(b , a%b);
}
int lcm(int a, int b)
{
return a/gcd(a,b)*b;//防止溢出
}
int m = sqrt(int n+0.5);
memset(vis, 0, sizeof(vis));
for(int i = 2; i <= m; i++)
{
if(!vis[i])
for(int j = i*i; j <= n; j += i)
{
vis[j] = 1;
}
}
//(a+b)%n=(a%n+b%n)%n
//(a-b)%n=(a%n-b%n+n)%n
//a*b%=(a%n)*(b%n)%n;
int mul_mod(int a, int b, int n)
{
a %= n;
b %= n;
return (int)((long long)a * b % n);
}
scanf("%s%d",n, &m);
int len = strlen(n);
int ans = 0;
for(int i = 0; i < len; i++)
{
ans=(int)((long long)ans*10 + n[i] - ‘0‘) % m);
}
printf("%d\n",ans);
标签:
原文地址:http://blog.csdn.net/xinag578/article/details/45974511