Singles' Day
来源:互联网 发布:java web项目实例大全 编辑:程序博客网 时间:2024/04/30 15:55
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 integersb and N, representing an integer M that only containsN 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".
暴力求解。。
#include <iostream>#include <cstdio>#include <cmath>using namespace std;bool isPrime[17][17];bool judge (long long m){ if (m == 1) return false; const long long sm = sqrt(m); for (int i = 2; i <= sm; ++i) { if (m % i == 0) { return false; } } return true;}long long convertToDecimal(int b, int n){ long long v = 0; while (n--) { v = v * b + 1; } return v;}int main(){ int b, n; for (b = 2; b < 17; ++b) { for (n = 1; n < 17; ++n) { long long v = convertToDecimal(b, n); isPrime[b][n] = judge(v); } } while (scanf("%d %d", &b, &n) != EOF) { if (isPrime[b][n]) { puts("YES"); } else { puts("NO"); } } return 0;}
- Singles' Day
- The Singles' Day :-)
- zoj 5194 Singles' Day
- zoj 3758 Singles' Day
- zoj3758 Singles' Day
- ZOJ3758:Singles' Day
- ZOJ3758 Singles' Day
- ZOJ 3758 Singles' Day
- ZOJ 3758 Singles' Day
- ZOJ 3758 Singles' Day
- zoj 3758 Singles' Day(暴力)
- ZOJ 3758 —— Singles' Day
- ZOJ3758:Singles' Day(快速素数判定法)
- ZOJ 3758 — Singles' Day(C++)
- ZOJ - 3758 - Singles' Day(素数判定)
- day
- day\\\
- day day day upupupup
- edittext光标问题
- 移动硬盘分区后丢失数据怎么恢复
- 软中断机制
- SPI及其时钟配置
- PHP开发环境搭建
- Singles' Day
- java开源测试工具汇总
- 摄像头开发-参考
- 解决FileUpload控件上传大文件被拒问题时
- Objective-C中不同方式实现锁(一)
- One-day-one-program(4)之链表的实现
- 简明 Vim 练级攻略
- Android 客户端开发
- VBS操作Excel常见方法