首页 > 代码库 > zoj 3758 Singles' Day

zoj 3758 Singles' Day

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5203

题意:有n个1然后按照b进制转化为10进制数,判断这个数是不是素数。

 1 #include <cstdio> 2 #include <cstring> 3 #define LL unsigned long long 4 using namespace std; 5  6 int b,n; 7 bool deal(LL n) 8 { 9     if(n==1) return false;10     for(LL i=2; i*i<=n; i++)11     {12         if(n%i==0)13         {14             return false;15         }16     }17     return true;18 }19 20 int main()21 {22     while(scanf("%d%d",&b,&n)!=EOF)23     {24         LL ans=1;25         for(int i=0; i<n; i++)26         {27             ans*=b;28         }29         ans=(ans-1)/(b-1);30         if(deal(ans)) printf("YES\n");31         else printf("NO\n");32     }33     return 0;34 }
View Code

 

zoj 3758 Singles' Day