欧拉函数,打表求欧拉函数poj3090】的更多相关文章

欧拉函数 φ(n) 定义:[1,N]中与N互质的数的个数 //互质与欧拉函数 /* 求欧拉函数 按欧拉函数计算公式,只要分解质因数即可 */ int phi(int n){ int ans=n; ;i<=sqrt(n);i++){ ){ ans=ans/i*(i-); ) n/=i; } } ) ans=ans/n*(n-); return ans; } 性质:1.[1,n]中与n互质的数的和为 n*φ(n)/2; 2.欧拉函数是积性函数    3.p|n && p*p|n =>…
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…
题意:给N个数,求对每个数ai都满足最小的phi[x]>=ai的x之和. 分析:先预处理出每个数的欧拉函数值phi[x].对于每个数ai对应的最小x值,既可以二分逼近求出,也可以预处理打表求. #include<bits/stdc++.h> using namespace std; typedef long long LL; ; int phi[maxn]; int res[maxn]; bool isprime[maxn]; void Euler(){ //欧拉函数筛 ;i<ma…
http://poj.org/problem?id=2478 此题只是用简单的欧拉函数求每一个数的互质数的值会超时,因为要求很多数据的欧拉函数值,所以选用欧拉函数打表法. PS:因为最后得到的结果会很大,所以结果数据类型不要用int,改为long long就没问题了 #include <iostream> #include <stdio.h> using namespace std; #define LL long long LL F[]; ]; void phi_table(in…
http://poj.org/problem?id=2478 题意:给定一个数x,求<=x的数的欧拉函数值的和.(x<=10^6) 题解:数据范围比较大,像poj1248一样的做法是不可行的了. 首先我们要了解欧拉函数的几个性质和推论:(今天跟好基友Konjak魔芋讨论了好久..) 推论(一): phi(p^k)=(p-1)*p^(k-1) 证明: 令n=p^k,小于等于n的正整数数中,所有p的倍数共有p^k /p = p^(k-1)个. 1~n出去p的倍数,所以phi(n)= n -  p^…
/** 大意: 求[a,b] 之间 phi(a) + phi(a+1)...+ phi(b): 思路: 快速求欧拉函数 **/ #include <iostream> #include <cstring> using namespace std; #define Max 3000000 ]; ]; ]; void init() { ; memset(flag,,sizeof(flag)); phi[]=; ;i<=Max;i++)//欧拉筛选 { if(flag[i]) {…
Description Bamboo Pole-vault is a massively popular sport in Xzhiland. And Master Phi-shoe is a very popular coach for his success. He needs some bamboos for his students, so he asked his assistant Bi-Shoe to go to the market and buy them. Plenty of…
The Euler function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description The Euler function phi is an important kind of function in number theory, (n) represents the amount of the numbers which are sm…
题意:你懂得. 析:一看这个题应该是欧拉phi函数,也就说欧拉phi函数是指求从 1 到 n 中与 n 互素的数的个数,这个题很明显是这个意思嘛,不多说了. 代码如下: #include <iostream> #include <cstdio> #include <cstring> using namespace std; const int maxn = 32768 + 5; int phi[maxn+5]; void phi_table(int n){ memset…
Problem I. Count Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 42    Accepted Submission(s): 16 Problem Description Multiple query, for each n, you need to getn i-1∑ ∑ [gcd(i + j, i - j) = 1…