ZOJ Problem Set - 3758 素数
2015-08-23 18:36
375 查看
Singles’ Day
Time Limit: 2 Seconds Memory Limit: 65536 KB
Singles’ Day(or One’s Day), an unofficial holiday in China, is a pop culture entertaining holiday on November 11 for young Chinese to celebrate their bachelor life. With the meaning of single or bachelor of number ‘1’ and the huge population of young single man. This festival is very popular among young Chinese people. And many Young bachelors organize parties and Karaoke to meet new friends or to try their fortunes that day.
On Singles’ Day, a supermarket has a promotional activity. Each customer will get a ticket on which there are two integers b and N, representing an integer M that only contains N digits 1 using b as the radix. And if the number M is a prime number, you will get a gift from the supermarket.
Since there are so many customers, the supermarket manager needs your help.
Input
There are multiple test cases. Each line has two integers b and N indicating the integer M, which might be very large. (2 <= b <= 16, 1 <= N <= 16)
Output
If the customer can get a gift, output “YES”, otherwise “NO”.
Sample Input
3 3
2 4
2 1
10 2
Sample Output
YES
NO
NO
YES
Hint
For the first sample, b=3, N=3, so M=(111)3, which is 13 in decimal. And since 13 is a prime number, the customer can get a gift, you should output “YES” on a line.
题意很简单,就是求长度为n的b进制数在每一位都是1的情况下,是不是素数
Time Limit: 2 Seconds Memory Limit: 65536 KB
Singles’ Day(or One’s Day), an unofficial holiday in China, is a pop culture entertaining holiday on November 11 for young Chinese to celebrate their bachelor life. With the meaning of single or bachelor of number ‘1’ and the huge population of young single man. This festival is very popular among young Chinese people. And many Young bachelors organize parties and Karaoke to meet new friends or to try their fortunes that day.
On Singles’ Day, a supermarket has a promotional activity. Each customer will get a ticket on which there are two integers b and N, representing an integer M that only contains N digits 1 using b as the radix. And if the number M is a prime number, you will get a gift from the supermarket.
Since there are so many customers, the supermarket manager needs your help.
Input
There are multiple test cases. Each line has two integers b and N indicating the integer M, which might be very large. (2 <= b <= 16, 1 <= N <= 16)
Output
If the customer can get a gift, output “YES”, otherwise “NO”.
Sample Input
3 3
2 4
2 1
10 2
Sample Output
YES
NO
NO
YES
Hint
For the first sample, b=3, N=3, so M=(111)3, which is 13 in decimal. And since 13 is a prime number, the customer can get a gift, you should output “YES” on a line.
题意很简单,就是求长度为n的b进制数在每一位都是1的情况下,是不是素数
#include <stdio.h> #include<math.h> int su(long long x); int main() { long long s,p; int n,m,i,j; while(~scanf("%d%d",&n,&m)) { s=0; while(m--) { s=s+pow(n,m); } if(su(s)==1) {printf("YES\n");} else {printf("NO\n");} } return 0; } int su(long long x) { long long i; if(x<2)return 0; for(i=2;i*i<=x;i++) { if(x%i==0) return 0; } return 1; }
相关文章推荐
- MFC 树控件我喜欢的两个函数
- Anaconda下 Gensim FAST_VERSION 无效的解决方法
- VMware虚拟机安装openstack注意事项
- hdu2063
- mysql双主半同步的灾备测试结论
- 第3周工作周报-2组-王亮晶
- 最大连续区间和问题 —— 转自purplest C++博客
- 韩鱼总结
- ROM简单制作教程
- 正则表达式re中的贪心算法和非贪心算法 在python中的应用
- 七和弦
- MongoDB的基本使用(二)
- poj 1753 Flip Game
- ASP.NET 开发必备知识点(1):如何让Asp.net网站运行在自定义的Web服务器上
- 显示rust测试时候的print信息
- 数据结构—线性结构—线性及其实现
- 在MAC下如何用SSH连接远程LINUX服务器
- ZOJ 3787 Access System
- php set_error_handler() 重要用法
- 打不开Eclipse,Eclipse闪退(已解决)