码迷,mamicode.com
首页 > 其他好文 > 详细

zoj 3758 Singles' Day

时间:2014-11-02 18:02:37      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   ar   os   for   sp   

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

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

bubuko.com,布布扣
 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

标签:style   blog   http   io   color   ar   os   for   sp   

原文地址:http://www.cnblogs.com/fanminghui/p/4069606.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!