D. Tanya and Password time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output While dad was at work, a little girl Tanya decided to play with dad
//// main.cpp// POJ 2337 欧拉路径//// Created by 郑喆君 on 8/7/14.// Copyright (c) 2014 itcast. All rights reserved.//#include<cstdio>#include<cstring>#include<iostream>#include<iomanip>#includ
定义 欧拉函数 ϕ(n)=count(p),p∈[1,n] AND gcd(p,n)=1 \phi(n)=count(p),p\in[1,n]\ \mathrm{AND} \ gcd(p,n)=1,其中 count(p) count(p)表示满足上述条件 p p的数目。公式ϕ(n)=n∏p|n(1−1p)\phi(n)=n\prod_{p|n}(1-\dfrac{1}{p}) 其中, p p
如果是求一个数字的欧拉函数,可以在时间复杂度为O(sqrt(n))求出。但是如果要求前n个数的欧拉函数,按照上述的思路,时间复杂度就是O(n*sqrt(n))。 因此采用一种线性时间的方法筛选欧拉函数值,完成打表。 本方法需要一下的几个性质: (p为质数) 1.phi[p]=p-1,因为1-p中只有p与本身不互质。 2.如果i mod p = 0,则 phi[i*p] = p *phi
题意: Given an integer N(1 < N < 2^31),you are to calculate ∑gcd(i, N) 1<=i <=N. 题解: 公式:f(N)=∑x*φ(N/x),x | N (x是N的约数) 因为在1···N中,gcd(i,N) = x, 的个数的等于φ(N / x) 另外还可以利用函数的积性: 对于正整数n的一个函数 f(n),当中f(1)=1且