uva10837 A Research Problem
来源:互联网 发布:卡西欧授权的淘宝网店 编辑:程序博客网 时间:2024/06/03 07:00
A mad researcher was trying to get fund for his research project but
it is a pity that after a year he was able to collect 500 $ only. So
all his research work has gone to ashtray. The mad researcher now
wants his revenge, so he wants you to solve his un nished research
problem within a very limited time. You will be happy to know that his
research is related to Eulers phi function. Euler’s phi (or totient)
function of a positive integer n is the number of integers in f 1 ; 2
; 3 ; : : : ; n g which are relatively prime to n . This is usually
denoted as φ ( n ). The table below shows the value of phi function
for rst few numbers. integer n 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
φ ( n ) 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Given the value of n , it is
very easy to nd the value of φ ( n ) using the formula below: φ ( n )
= n ∏ p j n (1
根据phi(n)=n * (p1-1)/p1 * (p2-1)/p2 * … * (pk-1)/pk,所有n的质因数-1一定是m的因数。找到sqrt(m)以内的所有质数,对每个质数是否取以及次数进行搜索,最后再判断一下大于sqrt(m)的因数【最多只有一个,次数最高为1】。
#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std;#define LL long longconst int maxp=100000,oo=0x3f3f3f3f;int p[100000],tot,a[100000],cnt,m,ans;bool have[100010];bool is(int x){ int i; int m=sqrt(x+0.1); for (i=1;i<=tot&&p[i]<=m;i++) if (x%p[i]==0) return 0; return 1;}void make(){ int i,j; for (i=2;i<=maxp;i++) { if (!have[i]) p[++tot]=i; for (j=1;j<=tot&&(LL)i*p[j]<=maxp;j++) { have[i*p[j]]=1; if (i%p[j]==0) break; } }}void init(){ int i; cnt=0; for (i=1;i<=tot;i++) if (m%(p[i]-1)==0) a[++cnt]=p[i];}void dfs(int k,LL n,LL phi){ if (phi==m) ans=min(ans,(int)n); if (k==cnt+1) { if (m%phi==0&&m/phi>a[cnt]&&is(m/phi+1)) ans=min(ans,(int)(n*(m/phi+1))); return; } dfs(k+1,n,phi); phi*=(a[k]-1); for (n*=a[k];n<=ans;n*=a[k],phi*=a[k]) dfs(k+1,n,phi);}int main(){ int K=0; make(); while (scanf("%d",&m)&&m) { printf("Case %d: %d ",++K,m); init(); ans=oo; dfs(1,1,1); printf("%d\n",ans); }}
- uva10837 A Research Problem
- A Research Problem UVA
- A Research Problem UVA
- How to identify a research problem
- UVA 10837(p345)----A Research Problem
- UVa 10837 A Research Problem 欧拉函数
- UVA 10837 - A Research Problem(欧拉函数)
- uva 10837 - A Research Problem(欧拉函数+暴力)
- uva 10837 A Research problem 欧拉函数+暴力
- Writing a Research Paper
- Writing a Research Essay
- What a Simple Research
- A Roadmap to Good Research
- WRITING A SCIENTIFIC RESEARCH ARTICLE
- A - Eddy's research II
- What a Simple Research HihoCoder
- Research
- Research
- 慕课网首页仿写—焦点图
- Opencv中SVM样本训练、归类流程及实现
- 欢迎使用CSDN-markdown编辑器
- 第十周项目2——二叉树的便利的递归算法
- 求满足条件的长度为N的字符串的个数(斐波那契数列)
- uva10837 A Research Problem
- mybatis 缓存getSqlSession().selectList(getMapperNamesapce() + ".getList", e);
- 整数分划问题和钱的组合问题(动态规划)
- Volley(三) 三级缓存策略
- 个人模板库
- 设置 UILabel 距离边框的距离
- Win10手动安装配置MySQL
- HDU 1867 A + B for you again
- JAVA-IO 文件拷贝功能的实现