当前位置:首页 > Problem Description Diophantus of Alexandria was an egypt mathematician living in Alexandria
Problem Description Diophantus of Alexandria was an egypt mathematician living in Alexandria. He was one of the first mathematicians to study equations where variables were restricted to inte
gral values. In honor of him, these equations are commonly called diophantine equations. One of the most famous diophantine equation is x^n + y^n = z^n. Fermat suggested that for n > 2, there are no solutions with positive integral values for x, y and z. A proof of this theorem (called Fermat's last theorem) was found only recently by Andrew Wiles. Consider the following diophantine equation: 1 / x + 1 / y = 1 / n where x, y, n ∈ N+ (1)
Diophantus is interested in the following question: for a given n, how many distinct solutions (i. e., solutions satisfying x ≤ y) does equation (1) have? For example, for n = 4, there are exactly three distinct solutions: 1 / 5 + 1 / 20 = 1 / 4 1 / 6 + 1 / 12 = 1 / 4 1/8+1/8=1/4
Clearly, enumerating these solutions can become tedious for bigger values of n. Can you help Diophantus compute the number of distinct solutions for big values of n quickly? Input The first line contains the number of scenarios. Each scenario consists of one line containing a single number n (1 ≤ n ≤ 10^9). Output The output for every scenario begins with a line containing \scenario starting at 1. Next, print a single line with the number of distinct solutions of equation (1) for the given value of n. Terminate each scenario with a blank line. Sample Input 2 4 1260 Sample Output Scenario #1: 3 Scenario #2: 113 题意,给一给 n,问有多少正整数对(x, y)满足 1/x + 1/y = 1/n, (x,y)跟(y,x)是一样的。 大致思路: 设 x=pk, y=qk (gcd(p,q) = 1) 那么 1/x+1/y = 1/pk+1/qk = (p+q)/pqk = 1/n ==> n = pqk/(p+q)... 因为 p,q 互质且 n 为整数。所以 n=p*q*(k/(p+q)).
pq 固定下来,k 也固定了。然后分解质因式 n=p1^r1*p2^r2*...*pt^rt..。枚举每个因子属于 p 还是 q 还是都不属于,同时枚举次数。最后相加起来就是答案。 代码: [cpp] view plaincopyprint? #include
int x = n; for (int i = 1; i <= tp&&sqr(pr[i]) <= x; ++i) if (x % pr[i] == 0) { tn[++tf] = 0; while (x % pr[i] == 0) { ++tn[tf]; x /= pr[i]; } } if (x > 1) tn[++tf] = 1; ans = 0; } void dg(int x, int p, int q, bool hasp) { if (x == tf + 1) ans += p * q; else { dg(x + 1, p, q, hasp); dg(x + 1, p * tn[x], q, true); if (hasp) dg(x + 1, p, q * tn[x], hasp); } } int main() { make_primes(); int T, ca = 0; scanf(\
{ printf(\return 0; }
共分享92篇相关文档