等式

求 1/a + 1/b = 1/n的正数解

设 x = a + n, y = b + n, 原式变为 a * b = n * n

答案微n * n 的约数个数加一之后的一半, 因为n * n 太大不能直接求因子个数需要通过质因子个数求约数个数。

 1 #include<bits/stdc++.h>
 2 #define LL long long
 3 #define fi first
 4 #define se second
 5 #define mk make_pair
 6 #define pii pair<int,int>
 7 using namespace std;
 8 
 9 const int N = 1000 + 7;
10 const int M = 100 + 7;
11 const int inf = 0x3f3f3f3f;
12 const LL INF = 0x3f3f3f3f3f3f3f3f;
13 const int mod = 1e9 + 7;
14 
15 
16 LL n, cnt[100], tot;
17 
18 int main() {
19     int T; scanf("%d", &T);
20     while(T--) {
21         tot = 0;
22         memset(cnt, 0, sizeof(cnt));
23         scanf("%lld", &n);
24         for(int i = 2; i * i <= n; i++) {
25             if(n % i == 0) {
26                 while(n % i == 0)
27                     cnt[tot]++, n /= i;
28                 tot++;
29             }
30         }
31         if(n != 1)
32             cnt[tot]++, tot++;
33 
34         for(int i = 0; i < tot; i++)
35             cnt[i] *= 2;
36         LL ans = 1;
37         for(int i = 0; i < tot; i++)
38             ans *= cnt[i] + 1;
39         printf("%lld\n", (ans + 1) / 2);
40     }
41     return 0;
42 }
43 
44 /*
45 */

 

posted @ 2018-04-12 16:44  NotNight  阅读(171)  评论(0编辑  收藏  举报