题意:

给你一个欧拉函数值 phi(n),问最小的n是多少。 phi(n) <= 100000000 , n <= 200000000


解题思路:

对于欧拉函数值可以写成

这里的k有可能是等于0的,所以不能直接将phi(n)分解质因子。但是可以知道(Pr - 1)是一定存在的,那就直接枚举素数,满足phi(n) % (Pr-1)的都加进去,然后对这些素数进行爆搜。。。说到底还是暴力啊。。。想不到什么巧妙的办法了,最后需要注意的是,一遍枚举完各个素数后phi(n)除后还剩now,现在要判断(now+1)是否为素数,还是保证这个素数前面没有访问过。具体实现过程见代码~

/* **********************************************
Author : JayYe
Created Time: 2013/9/25 0:00:42
File Name : JayYe.cpp
*********************************************** */ #include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; const int maxp = 10000 + 10;
bool vis[maxp], done[222];
int pri[maxp], pnum, cur_p[555], cnt_p[555]; void get_prime(int n) {
vis[1] = 1;
for(int i = 2;i*i <= n; i++) if(!vis[i])
for(int j = i*i;j <= n;j += i) vis[j] = 1;
pnum = 0;
for(int i = 2;i <= n; i++) if(!vis[i])
pri[pnum++] = i;
} int tot, ans; void split(int n) {
tot = 0;
for(int i = 0;i < pnum && (pri[i]-1)*(pri[i]-1) <= n; i++) if(n % (pri[i]-1) == 0) {
cur_p[tot++] = pri[i];
}
} int judge(int n) {
if(n == 1) return n;
n++;
// 判断剩余的值 + 1是否为素数
for(int i = 0;i < pnum && pri[i]*pri[i] <= n; i++) if(n % pri[i] == 0)
return -1;
for(int i = 0;i < tot; i++) if(vis[i] && n == cur_p[i]) // 判断这个素数是否已访问过
return -1;
return n;
} //left表示当前的n的值,now表示phi(n)剩余值
void dfs(int left, int now, int c) {
if(c == tot) {
int ret = judge(now);
// printf("left = %d now = %d ret = %d\n", left, now, ret);
if(ret > 0)
ans = min(ans, left*ret);
return ;
}
dfs(left, now, c+1);
if(now % (cur_p[c]-1) == 0) {
vis[c] = 1;
left *= cur_p[c];
now /= cur_p[c] - 1;
while(true) {
dfs(left, now, c+1);
if(now % cur_p[c]) return ;
now /= cur_p[c]; left *= cur_p[c];
}
vis[c] = 0;
}
} void solve(int n) {
memset(done, false, sizeof(done));
ans = 2000000000;
split(n);
dfs(1, n, 0);
} int main() {
get_prime(10000);
int n, cas = 1;
while(scanf("%d", &n) != -1 && n) {
solve(n);
printf("Case %d: %d %d\n", cas++, n, ans);
}
return 0;
}

UVa 10837 A Research Problem 欧拉函数的更多相关文章

  1. uva 10837 - A Research Problem(欧拉功能+暴力)

    题目链接:uva 10837 - A Research Problem 题目大意:给定一个phin.要求一个最小的n.欧拉函数n等于phin 解题思路:欧拉函数性质有,p为素数的话有phip=p−1; ...

  2. UVA 11424 GCD - Extreme (I) (欧拉函数+筛法)

    题目:给出n,求gcd(1,2)+gcd(1,3)+gcd(2,3)+gcd(1,4)+gcd(2,4)+gcd(3,4)+...+gcd(1,n)+gcd(2,n)+...+gcd(n-1,n) 此 ...

  3. UVA 11426 GCD - Extreme (II) (欧拉函数+筛法)

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=70017#problem/O 题意是给你n,求所有gcd(i , j)的和,其中 ...

  4. UVA 11426 GCD - Extreme (II)(欧拉函数打表 + 规律)

    Given the value of N, you will have to find the value of G. The definition of G is given below:Here ...

  5. poj 2480 Longge's problem [ 欧拉函数 ]

    传送门 Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7327   Accepted: 2 ...

  6. UVA 11426 - GCD - Extreme (II) 欧拉函数-数学

    Given the value of N, you will have to find the value of G. The definition of G is given below:G =i< ...

  7. UVa 10820 (打表、欧拉函数) Send a Table

    题意: 题目背景略去,将这道题很容易转化为,给出n求,n以内的有序数对(x, y)互素的对数. 分析: 问题还可以继续转化. 根据对称性,我们可以假设x<y,当x=y时,满足条件的只有(1, 1 ...

  8. UVa 10214 (莫比乌斯反演 or 欧拉函数) Trees in a Wood.

    题意: 这道题和POJ 3090很相似,求|x|≤a,|y|≤b 中站在原点可见的整点的个数K,所有的整点个数为N(除去原点),求K/N 分析: 坐标轴上有四个可见的点,因为每个象限可见的点数都是一样 ...

  9. UVA 11426 GCD - Extreme (II) 欧拉函数

    分析:枚举每个数的贡献,欧拉函数筛法 #include <cstdio> #include <iostream> #include <ctime> #include ...

随机推荐

  1. [Android] Service和IntentService中显示Toast的区别

    1. 表象     Service中可以正常显示Toast,IntentService中不能正常显示Toast,在2.3系统上,不显示toast,在4.3系统上,toast显示,但是不会消失. 2. ...

  2. Spring中的AOP

    什么是AOP? (以下内容来自百度百科) 面向切面编程(也叫面向方面编程):Aspect Oriented Programming(AOP),通过预编译方式和运行期动态代理实现程序功能的统一维护的一种 ...

  3. NSPredicate查询日期的问题

    查询日期的时候日期可以根据参数传进去,但不能在字符串中传参后在作为查询条件 简单比较以下两段代码 NSDate* date1=[NSDate date]; NSDate* date2=date1; r ...

  4. Android Studio中关于Project与Module

    在Android Studio中一个Project和Eclipse中的WorkSpace是相似的,而一个Module与Eclipse中的Project是相似的(大致可以这么的认为) 若在Android ...

  5. 在Global.asax文件里实现通用防SQL注入漏洞程序(适应于post/get请求)

    可使用Global.asax中的Application_BeginRequest(object sender, EventArgs e)事件来实现表单或者URL提交数据的获取,获取后传给SQLInje ...

  6. XML样本(格式没区别,但是一个有结果 一个没结果)

    xml样本01<orderlist>        <order>        <orderid>1</orderid>        <ord ...

  7. 基于GBT28181:SIP协议组件开发-----------第四篇SIP注册流程eXosip2实现(一)

    原创文章,引用请保证原文完整性,尊重作者劳动,原文地址http://www.cnblogs.com/qq1269122125/p/3945294.html. 上章节讲解了利用自主开发的组件SIP组件l ...

  8. ASP.NET MVC中的模型绑定

    模型绑定的本质   任何控制器方法的执行都受action invoker组件(下文用invoker代替)控制.对于每个Action方法的参数,这个invoker组件都会获取一个Model Binder ...

  9. centos账户的uid和gid

    修改/etc/passwd和/etc/group文件的UID和GID为0,可以获得root权限,不过不推荐~ UID和GID Linux系统如何区别不同的用户呢?可以很自然地想到,使用不同的用户名应该 ...

  10. 解决spring mvc 上传报错,Field [] isn't an enum value,Failed to convert value of type 'java.lang.String[]' to required type '

    没有选择附件,但是点击上传按钮的时候会报错. 之前不选择文件,直接上传空文件是可以的,后来不知道改了什么就不行了. 错误信息: -- :: [http--] TRACE org.springframe ...