The hacker Michael develops breakthrough password manager, which is called KEK (Keeper of Encrypted Keys). A distinctive feature of KEK is excellent security. To achieve this, Michael had to develop innovative encryption scheme. For example, in the well-known RSA scheme the sum of prime powers in the factorization is equal to 2, whereas in Michael’s scheme this sum is equal to 20!
However, the current version of the KEK runs very slow. Michael has found out that the problem is in the function of checking a modulus for correctness. This function should take the number n and answer, whether the sum of prime powers included in the factorization of n is equal to 20. Can you do this quickly?
Remember that the factorization of an integer is the representation of it in the form like p 1 α1 · p 2 α2 · ... · p k αk, where p i are prime numbers, and α i > 0. It is known that such representation is unique. Then the sum of powers looks likeα 1 + α 2 + ... + α k.

Input

The only line contains an integer n (1 ≤ n ≤ 10 18).

Output

If the sum of prime powers, included in the factorization of n, is equal to 20, then output “Yes”, otherwise output “No”.

Example

input output
2
No
1048576
Yes
10000000000
Yes

题意:给定数字N(1e18级),问将其唯一分解后(N=a1^p1*a2^p2...),幂的和(p1+p2+p3...)是否为20。

思路:根号N等于1e9级别,显然不能普通地分解因子来做。但是注意到20比较小,可以从20出发考虑:

将N分解后不可能有两个大于1e6的因子。因为1e6*1e6*2^18>2e18。认识到这一点,说明最多只有一个大于1e6的因子。所以只要在[1,1e6]找19个素数因子,然后判断剩下的数是不是素数即可。

#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
const int maxn=;
int p[maxn+],vis[maxn+],cnt;
void getprime()
{
for(int i=;i<=maxn;i++){
if(!vis[i]) p[++cnt]=i;
for(int j=;p[j]*i<=maxn;j++){
vis[i*p[j]]=;
if(i%p[j]==) break;
}
}
}
bool isprime(ll x)
{
for(int i=;i*i<=x;i++)
if(x%i==) return false;
return true;
}
int main()
{
getprime();
ll N; int num=;
scanf("%lld",&N);
if(N<*){
printf("No\n");
return ;
}
for(int i=;i<=cnt;i++){
while(N%p[i]==){
N/=p[i]; num++;
if(num==&&N==){ printf("Yes\n"); return ;}
if(num>=){ printf("No\n");return ;}
}
}
if(num<) printf("No\n");
else if(num==&&N>&&isprime(N)) printf("Yes\n");
else printf("No\n");
return ;
}

Ural2102:Michael and Cryptography(数论&素数)的更多相关文章

  1. ACM数论-素数

    ACM数论——素数  素数定义: 质数(prime number)又称素数,有无限个.质数定义为在大于1的自然数中,除了1和它本身以外不再有其他因数,这样的数称为质数.例 子:2.3.5.7.11.1 ...

  2. 【线性筛】【筛法求素数】【素数判定】URAL - 2102 - Michael and Cryptography

    暴力搞肯定不行,因此我们从小到大枚举素数,用n去试除,每次除尽,如果已经超过20,肯定是no.如果当前枚举到的素数的(20-已经找到的质因子个数)次方>剩下的n,肯定也是no.再加一个关键的优化 ...

  3. LightOJ-1259 Goldbach`s Conjecture 数论 素数筛

    题目链接:https://cn.vjudge.net/problem/LightOJ-1259 题意 给一个整数n,问有多少对素数a和b,使得a+b=n 思路 素数筛 埃氏筛O(nloglogn),这 ...

  4. ACM/ICPC 之 数论-素数筛选法 与 "打表"思路(POJ 1595)

    何为"打表"呢,说得简单点就是: 有时候与其重复运行同样的算法得出答案,还不如直接用算法把这组数据所有可能的答案都枚举出来存到一个足够大的容器中去-例如数组(打表),然后再输入数据 ...

  5. code vs1706 求合数和(数论 素数的判定)

    1706 求合数和  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 白银 Silver 题解  查看运行结果     题目描述 Description 用户输入一个数,然后输出 ...

  6. code vs1436 孪生素数 2(数论+素数的判定)

    1436 孪生素数 2  时间限制: 2 s  空间限制: 1000 KB  题目等级 : 白银 Silver 题解  查看运行结果     题目描述 Description 如m=100,n=6 则 ...

  7. 数论 - 素数的运用 --- poj 2689 : Prime Distance

    Prime Distance Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12512   Accepted: 3340 D ...

  8. P1218 [USACO1.5]特殊的质数肋骨 Superprime Rib (数论—素数 + DFS)

    这大概是我写的第一个DFS 题目描述 农民约翰的母牛总是产生最好的肋骨.你能通过农民约翰和美国农业部标记在每根肋骨上的数字认出它们.农民约翰确定他卖给买方的是真正的质数肋骨,是因为从右边开始切下肋骨, ...

  9. (第三场) H Diff-prime Pairs 【数论-素数线性筛法+YY】

    题目链接 题目描述 Eddy has solved lots of problem involving calculating the number of coprime pairs within s ...

随机推荐

  1. POJ3037 Skiing

    Skiing 题目大意: 给定一个M*N的网格,已知在每个网格中的点可以向上下左右四个方向移动一个单位,每个点都有一个高度值. 从每个点开始移动时存在一个速度值,从A点移动到B点,则此时B点的速度为& ...

  2. [codevs1050]棋盘染色 2

    [codevs1050]棋盘染色 2 试题描述 有一个5*N的棋盘,棋盘中的一些格子已经被染成了黑色,你的任务是对最少的格子染色,使得所有的黑色能连成一块. 输入 第一行一个整数N(<=100) ...

  3. POJ 3036 Honeycomb Walk

    http://poj.org/problem?id=3036 在每一个格子可以转移到与这个各自相邻的六个格子 那么设置转移变量 只需要六个 int d[6][2] = {-1, 0, -1, 1, 0 ...

  4. ESI+varnish页面片段缓存

    对于片段缓存,业界有成熟的解决方案,还有一个所谓的W3C标准:ESI(Edge Side Include) . ESI本身没有什么,只是一个XML的标签集合.ESI和SSI(Server Side I ...

  5. P1194 买礼物 洛谷

    https://www.luogu.org/problem/show?pid=1194 题目描述 又到了一年一度的明明生日了,明明想要买B样东西,巧的是,这B样东西价格都是A元. 但是,商店老板说最近 ...

  6. Permutation Sequence(超时,排列问题)

    The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  7. CodeForces 570D 【dfs序】

    题意: 给一颗树,根节点深度为1,每一个节点都代表一个子母. 数据输入: 节点数 询问数 从编号为2的节点开始依次输入其父节点的编号(共有节点数减1个数字输入) 字符串有节点数个小写字母 接下来询问 ...

  8. win7 休眠功能的开启与关闭

    1. 打开控制面板得下面目录,编辑计划设置

  9. 系统优化(一)Maven打包同一个jar有不同的:版本号+时间戳(解决思路)

    解决:maven仓库的ear里面有非常多个同样的jar(仅仅是包括不同的:版本号+时间戳) 问题描写叙述: 发现ear里面有非常多个同样的jar,仅仅是包括不同的:版本号+时间戳,例如以下图所看到的: ...

  10. [scrapy]实例:爬取jobbole页面

    工程概览: 创建工程 scrapy startproject ArticleSpider 创建spider cd /ArticleSpider/spiders/ 新建jobbole.py # -*- ...