ZOJ Problem Set - 3758 素数

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 <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;
}
时间: 2024-08-02 02:13:00

ZOJ Problem Set - 3758 素数的相关文章

ZOJ Problem Set - 3713

题意:给定一个字符串,用字符串ASC2码16进制数输出 ,并在前面输出字符串长度的16进制,输出长度的规则是 先输出长度的二进制数的后七位的十六进制(如果左边还有1 则这在后七位前面加上个1再输出  然后二进制数右移动七位,直到左边没有1)   注:所有16数都必须为两位! 解题思路:对长度进行输出处理 解题代码: #include<stdio.h> #include<string.h> #include<stdlib.h> #include<time.h>

ZOJ Problem Set - 3706

#include <cstdio> #include <cstdlib> #include <cstring> #include <set> #include <iostream> #include <algorithm> using namespace std; set<int> ST; int find(int a, int b, int c) { ST.clear(); ST.insert(0); ST.insert

ZOJ Problem Set - 3708 Density of Power Network

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 #include <stdio.h> #include <string.h> int main(int argc, char *argv[]) {     int T,i,j,lineSum;     int N,M;         int x[505],y[505];  

ZOJ Problem Set - 2397 Tian Ji -- The Horse Racing

#include<iostream> #include<cmath> #include<algorithm> #define REP(i,n) for(int i=0;i<(n);i++) using namespace std; int a[2000],b[2000],n; int main(){ while (cin>>n,n){ REP(i,n)cin>>a[i]; REP(i,n)cin>>b[i]; sort(a,a+

ZOJ Problem Set - 1730 Crazy Tea Party

#include<cstdio> int main(){ int T,n; scanf("%d",&T); while(T--){ scanf("%d",&n); printf("%d\n",n/2*(n/2-1)/2+(n-n/2)*(n-n/2-1)/2); } return 0; }

给一个素数 求s和t的最大公约数

题目链接:http://codeforces.com/contest/359/problem/C 题意: 给一个素数x,和a1.a2--an,计算这个式子 的时候,化成了 这个形式, 且t等于 xa1+a2+...+an,求s和t的最大公约数 (1≤n≤105, 2≤x≤109) ,结果对1000000007 取模 更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/ 分析: 直接分析s和t,并不能想到如何求g

UVa 10236 The Fibonacci Primes:斐波那契素数

10236 - The Fibonacci Primes Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1177 注意此题的描述和维基百科上Fibonacci Prime的描述不同. 上面加着重符的文字说明:可以用类似素数筛的方式筛出Fibonacci Pr

UVa 10038 / POJ 2575 / ZOJ 1879 Jolly Jumpers (water ver.)

10038 - Jolly Jumpers Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=979 http://poj.org/problem?id=2575 http://acm.zju.edu.cn/onlinejudge/showProblem.do?

算法:zoj 3201 Tree of Tree(树形背包dp)

题意 给一棵节点带权的树,找到一个有k个节点的子树,求这个子树的最大权值 思路 树形 dp+背包. f(i, j) 表示以i为根节点的有j个节点子树的最大权值 然后对i的每个子节点做分组背包, 因为对于i的每个儿子,可以选择分配 1,2,3...j-1个节点给它 f(i, j) = max{ max{f(i, j-p) + f(v, p) | 1<=p<j} | v是i的儿子节点} ans = max{ f[i][k] | 0<=i<n && i 子树节点个数>