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

ZOJ3758:Singles' Day

时间:2014-05-18 09:29:15      阅读:301      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   class   code   c   

Singles‘ Day

Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

Description

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.

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
using namespace std;

int main()
{
     int b,N;
     long long int t = 0;
     long long sum = 0;
    while(~scanf("%d%d",&b,&N))
    {
        sum = 1;
        t = 0;
        for(int i = 1;i<N;i++)
            sum = sum * b + 1;

          //  printf("%d\n",sum);
        int flag = 1;
        if(sum==1)
            puts("NO");
        else
        {
        t = sqrt(sum);
        for(int i = 2;i<=t;i++)
        {
            if(sum%i==0)
            {
                flag = 0;
                break;
            }
        }
        (flag==0)?puts("NO"):puts("YES");
        }
    }
    return 0;
}




ZOJ3758:Singles' Day,布布扣,bubuko.com

ZOJ3758:Singles' Day

标签:des   style   blog   class   code   c   

原文地址:http://blog.csdn.net/wjw0130/article/details/26069675

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