题意:

给你一个欧拉函数值 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. JQuery中_Radio、DropDownList、Checkbox选择控件的处理

    Radio  1.获取选中值,三种方法都可以: $('input:radio:checked').val(): $("input[type='radio']:checked").v ...

  2. sync fsync fdatasync ---systemtap跟踪

    aa.stp: probe kernel .function ( "sys_sync" ) { printf ( "probfunc:%s fun:%s\n", ...

  3. Linux禁止ping服务

    ping是一个通信协议,是ip协议的一部分,tcp/ip 协议的一部分.利用它可以检查网络是否能够连通,用好它可以很好地帮助我们分析判定网络故障.应用格式为:Ping IP地址.但服务启用ping有时 ...

  4. C#自定义事件:属性改变引发事件示例

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...

  5. 超级钢琴 2010年NOI

    /* 自己yy的奇葩做法居然A了23333 不过空间好像很大 时间好像略慢..... 毕竟不是正解 前缀维护sum值 枚举区间起点 然后终点的坐标可以确定在一个范围 可持久化线段树查询区间第1大 然后 ...

  6. asp.net C# 导出EXCEL数据

    if (dt == null) { return ""; } Microsoft.Office.Interop.Excel.Application xlApp = new Micr ...

  7. 一、初识T4引擎

    对于代码生成器我们并不陌生,在日常编码中这也是用的比较多的工具之一.一般代码生成器主要功能是生成公共或基础代码来减少编码人员的工作量,而一款优秀的代码生成器除了生产代码以外,同时兼具生成项目架构和基础 ...

  8. c-指针的指针

    概述: 贴上一个'经典C语言程序设计100例'的第77个程序 #include <stdio.h> int main(void) { char *s[]={"man", ...

  9. thinkphp中ajax用户名校验

    ajax实在是太神奇了,刚刚接触,不足之处,请大家指正. 采用Ajax方式进行页面无刷新提示,来检测用户名是否存在. 搭建一个thinkphp的环境,在index.html中,ajax代码如下: &l ...

  10. 模拟vector

    实现了vector的模板,insert, erase, push_back, iterator #include<iostream> #include<string.h> #i ...