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. python005 Python3 注释

    Python3 注释确保对模块, 函数, 方法和行内注释使用正确的风格Python中的注释有单行注释和多行注释:Python中单行注释以 # 开头,例如:: # 这是一个注释 print(" ...

  2. XV6锁

    锁 xv6 运行在多处理器上,即计算机上有多个单独执行代码的 CPU.这些 CPU 操作同一片地址空间并分享其中的数据结构:xv6 必须建立一种合作机制防止它们互相干扰.即使是在单个处理器上,xv6 ...

  3. 【课余作品】简约QQ申请器(永久免费更新)

    UPDATEDATE:2013-08-28 下载地址:http://pan.baidu.com/share/link?shareid=3376000151&uk=3339155803

  4. C# CreateDataTable

    public DataTable CreateDataTable()         {             DataTable dataTable = new DataTable();      ...

  5. bzoj 4736 /uoj274【清华集训2016】温暖会指引我们前行 lct

    [清华集训2016]温暖会指引我们前行 统计 描述 提交 自定义测试 寒冬又一次肆虐了北国大地 无情的北风穿透了人们御寒的衣物 可怜虫们在冬夜中发出无助的哀嚎 “冻死宝宝了!” 这时 远处的天边出现了 ...

  6. Intent和IntentFilter简介

    Intent和IntentFilter简介 Intent和IntentFilter简介 意图Intent分类: 显式意图:利用class找到对方,在同一个应用程序类可以方便使用,但是在不同的应用程序无 ...

  7. Drainage Ditches--hdu1532(网络流 模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=1532 Drainage Ditches Time Limit: 2000/1000 MS (Java/Other ...

  8. 2017-10-04-morning

    改题面只有1改为0 .. #include <cstring> #include <cstdio> inline void read(int &x) { x=; reg ...

  9. Defcon 23最新开源工具NetRipper代码分析与利用

    0×01 研究背景 在分析了俄罗斯人被曝光的几个银行木马的源码后,发现其大多均存在通过劫持浏览器数据包来获取用户个人信息的模块,通过截获浏览器内存中加密前或解密后的数据包来得到数据包的明文数据.在De ...

  10. Excel中INDEX函数的使用

    1 函数INDEX( )有两种形式: 数组形式——INDEX(array,row_num,column_num)和 引用形式——INDEX(reference,row_num,column_num,a ...