博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ZOJ Problem Set - 3758 素数
阅读量:6595 次
发布时间:2019-06-24

本文共 1838 字,大约阅读时间需要 6 分钟。

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的情况下,是不是素数

#include 
#include
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;}

转载地址:http://zijio.baihongyu.com/

你可能感兴趣的文章
面向对象设计模式纵横谈:Factory Method 工厂方法模式(笔记记录)
查看>>
C++使用hiredis连接带密码的redis服务
查看>>
SQL SERVER 批量生成编号
查看>>
thinkjs——一个字段一种数字代表两种状态
查看>>
C++的那些事:类的拷贝控制
查看>>
numpy得到数组的index
查看>>
JSP页面重定向
查看>>
RecyclerView具体解释
查看>>
vue2.0 vue-loader
查看>>
美国埃博拉患者是怎样治愈的?
查看>>
[离散时间信号处理学习笔记] 9. z变换性质
查看>>
简单实用SQL脚本Part:查找SQL Server 自增ID值不连续记录
查看>>
关系型数据库的分片原则
查看>>
浅谈线段树中加与乘标记的下放
查看>>
【IDEA】IDEA中maven项目pom.xml依赖不生效解决
查看>>
scrapy-redis(七):部署scrapy
查看>>
Redis集群
查看>>
建立自己的NuGet服务器
查看>>
【编程之美】中国象棋将帅问题
查看>>
DroidCam 一片 红色 解决办法
查看>>