Ural2102:Michael and Cryptography(数论&素数)
Input
Output
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(数论&素数)的更多相关文章
- ACM数论-素数
ACM数论——素数 素数定义: 质数(prime number)又称素数,有无限个.质数定义为在大于1的自然数中,除了1和它本身以外不再有其他因数,这样的数称为质数.例 子:2.3.5.7.11.1 ...
- 【线性筛】【筛法求素数】【素数判定】URAL - 2102 - Michael and Cryptography
暴力搞肯定不行,因此我们从小到大枚举素数,用n去试除,每次除尽,如果已经超过20,肯定是no.如果当前枚举到的素数的(20-已经找到的质因子个数)次方>剩下的n,肯定也是no.再加一个关键的优化 ...
- LightOJ-1259 Goldbach`s Conjecture 数论 素数筛
题目链接:https://cn.vjudge.net/problem/LightOJ-1259 题意 给一个整数n,问有多少对素数a和b,使得a+b=n 思路 素数筛 埃氏筛O(nloglogn),这 ...
- ACM/ICPC 之 数论-素数筛选法 与 "打表"思路(POJ 1595)
何为"打表"呢,说得简单点就是: 有时候与其重复运行同样的算法得出答案,还不如直接用算法把这组数据所有可能的答案都枚举出来存到一个足够大的容器中去-例如数组(打表),然后再输入数据 ...
- code vs1706 求合数和(数论 素数的判定)
1706 求合数和 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 白银 Silver 题解 查看运行结果 题目描述 Description 用户输入一个数,然后输出 ...
- code vs1436 孪生素数 2(数论+素数的判定)
1436 孪生素数 2 时间限制: 2 s 空间限制: 1000 KB 题目等级 : 白银 Silver 题解 查看运行结果 题目描述 Description 如m=100,n=6 则 ...
- 数论 - 素数的运用 --- poj 2689 : Prime Distance
Prime Distance Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12512 Accepted: 3340 D ...
- P1218 [USACO1.5]特殊的质数肋骨 Superprime Rib (数论—素数 + DFS)
这大概是我写的第一个DFS 题目描述 农民约翰的母牛总是产生最好的肋骨.你能通过农民约翰和美国农业部标记在每根肋骨上的数字认出它们.农民约翰确定他卖给买方的是真正的质数肋骨,是因为从右边开始切下肋骨, ...
- (第三场) H Diff-prime Pairs 【数论-素数线性筛法+YY】
题目链接 题目描述 Eddy has solved lots of problem involving calculating the number of coprime pairs within s ...
随机推荐
- irules事件和命令
- HTTP错误:java.lang.IllegalArgumentException: Illegal character in scheme at index 0: http://xxxxxx
读取T卡文件里的域名,HTTP请求出现如下错误 java.lang.IllegalArgumentException: Illegal character in scheme at index 0: ...
- python学习之-- mysql模块和sqlalchemy模块
简单介绍python下操作mysql数据库模块有2个:pyhton-mysqldb 和 pymysql 说明:在python3中支持mysql 的模块已经使用pymysql替代了MysqlDB(这个 ...
- Python高级进阶(一)Python框架之Django入门
传说中的Django Django由来 Django是一个开放源代码的Web应用框架,由Python写成.采用了MVC的框架模式,即模型M,视图V和控制器C.它最初是被开发来用于管理劳伦斯出版集团旗下 ...
- react 使用 eslint 的三种代码检查方案总结,多了解点--让代码更完美....
1.介绍 ESLint 是一个可扩展,每条规则独立,被设计为完全可配置的lint工具. 可以用来检测代码,避免低级错误 可以用来规范代码的开发风格,统一代码习惯. 2.为什么使用 ESLint ? 统 ...
- eclipse设置每次提交代码忽略target、.settings、.svn、.project文件
- 解决Coldfusion连接MySQL数据库的问题
在连接MySQL时,出现了如下错误: Connections to MySQL Community Server are not supported. Please contact MySQL to ...
- openwrt下载编译
1. 安装依赖包: yum install autoconf binutils bison bzip2 flex gawk gcc gcc-c++ gettext make ncurses-devel ...
- VB6 如何自定义代码字体和支持鼠标滚轮
1 点击工具-选项-编辑器格式,把代码改成需要的字体和大小.(一般微软雅黑,16号字体比较好) 2 从以下网站下载VB6增强工具,可以支持鼠标滚轮代替右侧滚动条查看代码,按F3还可以切换代码窗口和 ...
- win8 metro 自己写摄像头录像项目
这是要求不适用CameraCaptureUI等使用系统自带的 camera UI界面.要求我们自己写调用摄像头摄像的方法,如今我把我的程序贴下: UI界面的程序: <Page x:Class= ...