SGU---102 欧拉函数】的更多相关文章

感觉自己弱爆了,做做SGU吧... #include<iostream> #include<cmath> //欧拉函数 using namespace std; int euler(int n) { int m=n; int ans=n; for(int i=2;i<=sqrt(n*1.0);i++) //注意等于号, { if(m%i==0) { ans=ans*(i-1)*1.0/i; while(m%i==0)m/=i; } } if(m!=1)ans=ans*(m-1…
Sample Input 3 4 5 18 36 360 2147483647 Sample Output 1 1 2 3 6 48 1073741823 题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3937 题目大意:圆上有N个点把圆分成N等分,求隔同样的点能一笔画全然部点的方法: 思考:要一笔画出,那么(N.K)必然没有在…
102. Coprimes time limit per test: 0.25 sec. memory limit per test: 4096 KB For given integer N (1<=N<=104) find amount of positive numbers not greater than N that coprime with N. Let us call two positive integers (say, A and B, for example) coprime…
GCD 题意:输入N,M(2<=N<=1000000000, 1<=M<=N), 设1<=X<=N,求使gcd(X,N)>=M的X的个数.  (文末有题) 知识点:   欧拉函数.http://www.cnblogs.com/shentr/p/5317442.html 题解一: 当M==1时,显然答案为N. 当M!=1.  X是N的因子的倍数是 gcd(X,N)>1 && X<=N 的充要条件.so  先把N素因子分解, N=     …
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 2553  Solved: 1565[Submit][Status][Discuss] Description Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题.现在问题来了:给定一个整数N,你需要求出∑gcd(i, N)(1<=i <=N). Input 一个整数,为N. Output 一个整数,为所求的答案. Sample Inp…
2818: Gcd Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 4436  Solved: 1957[Submit][Status][Discuss] Description 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. 1<=N<=10^7 uva上做过gcd(x,y)=1的题 gcd(x,y)=p ---> gcd(x/p,y/p)=1 每个质数做一遍行了 答案是欧拉函数的前缀和*2…
题目:http://cogs.pw/cogs/problem/problem.php?pid=2533 这道题考察打表观察规律. 发现对f的定义实际是递归式的 f(n,k) = f(0,f(n-1,k)) f(0,k) = balabalabalabala 所以,实际上的f(n,k)是这么个东西 f(0,(0,(0,(0,(0,(0,(0,(0,k)))))))) 直接递归求解并打出表来,我们可以发现这样的事实 f(0,k) = k+1 所以有f(n,k) = n + k + 1; 所以题目就转…
Farey Sequence 题意:给定一个数n,求在[1,n]这个范围内两两互质的数的个数.(转化为给定一个数n,比n小且与n互质的数的个数) 知识点: 欧拉函数: 普通求法: int Euler(int n) { int ans=n; for(int i=0;i<cnt&&prime[i]<=n;i++) { if(n%prime[i]==0) { ans=ans-ans/prime[i]; while(n%prime[i]==0) n/=prime[i]; } } if(…
51Nod: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1136 1136 欧拉函数 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题   对正整数n,欧拉函数是少于或等于n的数中与n互质的数的数目.此函数以其首名研究者欧拉命名,它又称为Euler's totient function.φ函数.欧拉商数等.例如:φ(8) = 4(Phi(8) = 4),因为1,3,5,7均和8互质.  …
欧拉函数的作用: 有[1,2.....n]这样一个集合,f(n)=这个集合中与n互质的元素的个数.欧拉函数描述了一些列与这个f(n)有关的一些性质,如下: 1.令p为一个素数,n = p ^ k,则   f(n) = p ^ k - p ^ (k-1) 2.令m,n互质,则   f(m*n) = f(m) * f(n) 3.如果n为奇数,则    f(2 * n) = f(n) 下面给出一个例题的代码,例题链接:http://acm.hdu.edu.cn/showproblem.php?pid=…
Description   Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=1000000000,1<=B<=10^1000000). Input There are multiply testcases. Each testcase, there is one line contains three integers A, B and C, separated by a sin…
Description has only two SentencesTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 852 Accepted Submission(s): 259 Problem Descriptionan = X*an-1 + Y and Y mod (X-1) = 0.Your task is to calculate th…
通式: $\phi(x)=x(1-\frac{1}{p_1})(1-\frac{1}{p_2})(1-\frac{1}{p_3}) \cdots (1-\frac{1}{p_n})$ 若n是质数p的k次幂:$\phi(n)=p^k-p^{k-1}=(p-1)p^{k-1}$,因为除了p的倍数外,其他数都跟n互质. 设n为正整数,以$\phi(n)$表示不超过n且与n互素的正整数的个数,称为n的欧拉函数值,这里函数φ:N→N,n→φ(n)称为欧拉函数. 欧拉函数是积性函数——若m,n互质, $\p…
A - Bi-shoe and Phi-shoe Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1370 Appoint description:  System Crawler  (2016-07-08) Description Bamboo Pole-vault is a massively popular sport in X…
1040 最大公约数之和 题目来源: rihkddd 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题  收藏  关注 给出一个n,求1-n这n个数,同n的最大公约数的和.比如:n = 6 1,2,3,4,5,6 同6的最大公约数分别为1,2,3,2,1,6,加在一起 = 15   Input 1个数N(N <= 10^9) Output 公约数之和 Input示例 6 Output示例 15 思路: 目的是求∑(i= 1,n) gcd( i , n ): gc…
题意 求$ \sum_{i=1}^n gcd(i,n) $ 给定 $n(1\le n\le 2^{32}) $. 链接 题解 欧拉函数 $φ(x)$ :1到x-1有几个和x互质的数. gcd(i,n)必定是n的一个约数. 若p是n的约数,那么gcd(i,n)==p的有$φ(n/p)$个数,因为要使gcd(i,n)==p,i/p和n/p必须是互质的. 那么就是求i/p和n/p互质的i在[1,n]里有几个,就等价于 1/p,2/p,...,n/p 里面有几个和n/p互质,即φ(n/p). 求和的话,…
这题满满的黑科技orz 题意:给出L,要求求出最小的全部由8组成的数(eg: 8,88,888,8888,88888,.......),且这个数是L的倍数 sol:全部由8组成的数可以这样表示:((10^x)-1)*(8/9) 那么有m=((10^x)-1)*(8/9)=k*L,answer即满足条件的最小的x 性质1:若ax=by且a和b互质,那么说明a中没有任何b的质因子,b的质因子一定都在x里.所以x是b的倍数. 所以先想方设法在等式中构造两个互质的数以便化简.我们取p=8/gcd(8,L…
题意:给出N,求所有满足i<j<=N的gcd(i,j)之和 这题去年做过一次... 设f(n)=gcd(1,n)+gcd(2,n)+......+gcd(n-1,n),那么answer=S[N]=f(1)+f(2)+...+f(N). 先求出每一个f(n). 令g(n,i)=[满足gcd(x,n)=i且x<N的x的数量],i是n的约数 那么f(n)=sigma[i*g(n,i)] (i即gcd的值,g(n,i)为数量) 又注意到gcd(x,n)=i -> gcd(x/i,n/i)=…
大白书P125 #include <iostream> #include <cstring> using namespace std; #define MMX 4000010 #define LL long long int phi[MMX],f[MMX]; LL S[MMX]; void calc_phi(int n) //求1--n的欧拉函数,phi[i]=φ(i) { ;i<=n;i++) phi[i]=; phi[]=; ;i<=n;i++) if (!phi[…
Reflect Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 288    Accepted Submission(s): 174 Problem Description We send a light from one point on a mirror material circle,it reflects N times and…
O(n) 筛选素数 #include<bits/stdc++.h> using namespace std; const int M = 1e6 + 10 ; int mindiv[M] ;//每个数的最小质因数 int prim[M] , pnum ;//存素数 bool vis[M] ; void prim () { for (int i = 2 ; i < M ; i ++) { if (!vis[i]) { mindiv[i] = i ; prim[ pnum++ ] = i ;…
题目 Source http://www.lightoj.com/volume_showproblem.php?problem=1298 Description A number is Almost-K-Prime if it has exactly K prime numbers (not necessarily distinct) in its prime factorization. For example, 12 = 2 * 2 * 3 is an Almost-3-Prime and…
题意: 求1-n内互质数对个数 SOL: 裸欧拉函数,还有莫比乌斯反演的加速什么的,挖个坑. Code: /*========================================================================== # Last modified: 2016-03-16 20:57 # Filename: 2190.cpp # Description: ==================================================…
题目链接: http://poj.org/problem?id=2480 题目大意:求Σgcd(i,n). 解题思路: 如果i与n互质,gcd(i,n)=1,且总和=欧拉函数phi(n). 如果i与n不互质,那么只要枚举n的全部约数,对于一个约数d,若使gcd(i/d,n/d)互质,这部分的gcd和=d*欧拉函数phi(n/d). 不断暴力从小到大枚举约数,这样就把gcd和切成好多个部分,累加起来就行了. 其实还可以公式化简,不过实在太繁琐了.可以参考金海峰神的解释. 由于要求好多欧拉函数,每次…
题目链接: http://poj.org/problem?id=2407 题目大意:求小于n且与n互质的正整数个数. 解题思路: 欧拉函数=小于n且与n互质的正整数个数. 公式=n*(1-1/P1)*(1-1/P2)....*(1-1/Pn),其中Pn为不同的质因数. 欧拉函数的求法有好多. 最简单的是手艹质因数分解,然后套公式计算. 注意特判1的时候ans=0. #include "cstdio" #include "map" using namespace st…
对正整数n,欧拉函数是少于或等于n的数中与n互质的数的数目.此函数以其首名研究者欧拉命名,它又称为Euler's totient function.φ函数.欧拉商数等.例如:φ(8) = 4(Phi(8) = 4),因为1,3,5,7均和8互质.   Input 输入一个数N.(2 <= N <= 10^9) Output 输出Phi(n). Input示例 8 Output示例 4 代码 #include<iostream> #include<cstring> #in…
题目链接 猜了一个结论,题面跟欧拉函数有关系. import java.util.*; import java.math.*; import java.text.*; import java.io.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int p[] = new int[1001]; int prim[] = new int[100…
1.HDU 2824   The Euler function 2.链接:http://acm.hdu.edu.cn/showproblem.php?pid=2824 3.总结:欧拉函数 题意:求(a,b)间的欧拉函数值的和. #include<iostream> #include<cstring> #include<cmath> #include<queue> #include<algorithm> #include<cstdio>…
2^x mod n = 1 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9231    Accepted Submission(s): 2837 Problem Description Give a number n, find the minimum x(x>0) that satisfies 2^x mod n = 1.   In…
Relatives Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11372   Accepted: 5544 Description Given n, a positive integer, how many positive integers less than n are relatively prime to n? Two integers a and b are relatively prime if ther…