题目链接:uva 10837 - A Research Problem 题目大意:给定一个phin.要求一个最小的n.欧拉函数n等于phin 解题思路:欧拉函数性质有,p为素数的话有phip=p−1;假设p和q互质的话有phip∗q=phip∗phiq 然后依据这种性质,n=pk11(p1−1)∗pk22(p2−1)∗⋯∗pkii(pi−1),将全部的pi处理出来.暴力搜索维护最小值,尽管看上去复杂度很高,可是由于对于垒乘来说,增长很快,所以搜索范围大大被缩小了. #include <cstdi…
题意: 给你一个欧拉函数值 phi(n),问最小的n是多少. phi(n) <= 100000000 , n <= 200000000 解题思路: 对于欧拉函数值可以写成 这里的k有可能是等于0的,所以不能直接将phi(n)分解质因子.但是可以知道(Pr - 1)是一定存在的,那就直接枚举素数,满足phi(n) % (Pr-1)的都加进去,然后对这些素数进行爆搜...说到底还是暴力啊...想不到什么巧妙的办法了,最后需要注意的是,一遍枚举完各个素数后phi(n)除后还剩now,现在要判断(no…
https://vjudge.net/problem/UVA-10837 求最小的n,使phi(n)=m #include<cstdio> #include<algorithm> #define N 10011 int prime[N],cnt; bool v[N],vis[N]; int p[N],tot,ans; void pre_prime() { ;i<N;i++) { if(!v[i]) prime[++cnt]=i; ;j<=cnt;j++) { if(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) 此题和UVA 11426 一样,不过n的范围只有20000,但是最多有20000组数据. 当初我直接照搬UVA11426,结果超时,因为没有预处理所有的结果(那题n最多4000005,但最多只有100组数据),该题数据太多了额... 思路:令sum(n)=gcd(1,n)+gcd(2,n)+...+g…
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=70017#problem/O 题意是给你n,求所有gcd(i , j)的和,其中1<=i <j <n. 要是求gcd(n , x) = y的个数的话,那么就是求gcd(n/y , x/y) = 1的个数,也就是求n/y的欧拉函数.这里先预处理出欧拉函数,然后通过类似筛法的技巧筛选出答案累加起来. #include <iostream> #include &l…
传送门:http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=3151 时间限制(普通/Java):1000MS/3000MS     内存限制:65536KByte 描述 H1N1 like to solve acm problems.But they are very busy, one day they meet a problem. Given three intergers a,b,c, the…
Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6383   Accepted: 2043 Description Longge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms. Now…
Given the value of N, you will have to find the value of G. The definition of G is given below:Here GCD(i, j) means the greatest common divisor of integer i and integer j.For those who have trouble understanding summation notation, the meaning of G i…
传送门 Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7327   Accepted: 2416 Description Longge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms.…
Given the value of N, you will have to find the value of G. The definition of G is given below:G =i<N∑i=1j∑≤Nj=i+1GCD(i, j)Here GCD(i, j) means the greatest common divisor of integer i and integer j.For those who have trouble understanding summation no…