HDU 1299 基础数论 分解
给一个数n问有多少种x,y的组合使$\frac{1}{x}+\frac{1}{y}=\frac{1}{n},x<=y$满足,设y = k + n,代入得到$x = \frac{n^2}{k} + n$,也就是求n^2的因子数量
/** @Date : 2017-09-08 10:45:12 * @FileName: HDU 1299 数论 分解.cpp * @Platform: Windows * @Author : Lweleth (SoungEarlf@gmail.com) * @Link : https://github.com/ * @Version : $Id$ */ #include <bits/stdc++.h> #define LL long long #define PII pair<int ,int> #define MP(x, y) make_pair((x),(y)) #define fi first #define se second #define PB(x) push_back((x)) #define MMG(x) memset((x), -1,sizeof(x)) #define MMF(x) memset((x),0,sizeof(x)) #define MMI(x) memset((x), INF, sizeof(x)) using namespace std; const int INF = 0x3f3f3f3f; const int N = 1e5+20; const double eps = 1e-8; int pri[N]; int vis[N]; int c = 0; void prime() { MMF(vis); for(int i = 2; i < N; i++) { if(!vis[i]) vis[i] = 1, pri[c++] = i; for(int j = 0; j < c && i * pri[j] < N; j++) { vis[i*pri[j]] = 1; if(i % pri[j] == 0) break; } } } int main() { prime(); int T; cin >> T; int icase = 0; while(T--) { LL n; scanf("%lld", &n); LL t = n * n;//直接对n^2分解不对? LL cnt = 1; for(int i = 0; i < c && pri[i] * pri[i] <= n; i++) { if(n % pri[i] == 0) { LL tmp = 0; while(n % pri[i] == 0 && n) n /= pri[i], tmp++; cnt *= tmp*2+1; } } if(n > 1) cnt *= 3; cnt = (cnt + 1) / 2; printf("Scenario #%d:\n", ++icase); printf("%lld\n\n", cnt); } return 0; }