UVa10006-Carmichael Numbers
生活随笔
收集整理的這篇文章主要介紹了
UVa10006-Carmichael Numbers
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=947
快速冪取模
code:
?
#include <iostream> #include <cstring> #include <cmath> using namespace std; typedef long long LL; LL pow_mod(LL a, LL b, LL m) {LL res = 1;for(;b;b>>=1,a=(a*a)%m)if(b&1) res =(res*a) %m;/*while(b){if(b&1) res =res*a %m;a = a*a % m;b >>=1;}*/return res; } #define N 65000 bool prime[N]; void sieve_prime() {memset(prime,1,sizeof(prime));for(int i=2;i<=sqrt(N); i++)if(prime[i])for(int j=i*i; j<=N; j+=i)prime[j] = 0; } int main() {int n;sieve_prime();while(cin>>n,n) {if(prime[n]){cout<<n<<" is normal."<<endl;continue;}bool flag = 1;for(int i=2; i<n; i++) {if(pow_mod(i,n,n)!=i) {flag = 0;break;}}if(flag) cout<<"The number "<<n<<" is a Carmichael number."<<endl;elsecout<<n<<" is normal."<<endl;} }?
?
轉(zhuǎn)載于:https://www.cnblogs.com/jiangu66/p/3159689.html
總結(jié)
以上是生活随笔為你收集整理的UVa10006-Carmichael Numbers的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《那些年啊,那些事——一个程序员的奋斗史
- 下一篇: 在窗口间移动按扭