标签:
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);
int pow_mod(long long a,long long n,int m)
{
if(n==0) return 1;
long long int x=pow_mod(a,n/2,m);
long long int ans=x*x%m;
ans=ans%m;
if(n%2==1) ans=ans*a%m;
return (int)ans;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/xinag578/article/details/45974511