链接:https://www.nowcoder.com/acm/contest/90/F
来源:牛客网
题目描述
给定n,求1/x + 1/y = 1/n (x<=y)的解数。(x、y、n均为正整数)
输入描述:
在第一行输入一个正整数T。接下来有T行,每行输入一个正整数n,请求出符合该方程要求的解数。(1<=n<=1e9)
输出描述:
输出符合该方程要求的解数。
示例1
输入
3 1 20180101 1000000000
输出
1 5 181
思路:
1/x + 1/y = 1/n
-> yn + xn - xy = 0
-> yn + xn - xy -n^2 +n^2 = 0
-> n^2 = (n - x) * ( n - y)
即:求n^2的约数组合数,n^2的质因数与n的质因数相同,个数为n的两倍
代码:
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define is_lower(c) (c >= 'a' && c <= 'z') #define is_upper(c) (c >= 'A' && c <= 'Z') #define is_alpha(c) (is_lower(c) || is_upper(c)) #define is_digit(c) (c >= '0' && c <= '9') #define min(a, b) ((a) < (b) ? (a) : (b)) #define max(a, b) ((a) > (b) ? (a) : (b)) #define PI acos(-1) #define IO \ ios::sync_with_stdio(); \ cin.tie(); \ cout.tie(); #define For(i, a, b) for (int i = a; i <= b; i++) typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; const ll inf = 0x3f3f3f3f; ; const ll inf_ll = (ll)1e18; const ll maxn = 100005LL; const ll mod = 2012LL; + ; int main() { int T,n; cin>>T; while(T--) { cin>>n; ]={}; ; ; i * i <= n; i++) { ) { ) { ans[len]++; n /= i; } len++; } } ) ans[len]++; ll res = ; ; i <= len ; i++) res *= ans[i] * + ; res = (res + ) / ; cout << res << endl; } }