1236 - Pairs Forming LCM -- LightOj1236 (LCM)
http://lightoj.com/volume_showproblem.php?problem=1236
题目大意: 给你一个数n,让你求1到n之间的数(a,b && a<=b)两个数的最小公倍数等于n有多少对这样的ab.
分析都写在图片上了,费了我好大的事呢
ac代码
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<algorithm> #include<stdio.h> #include<string.h> #include<stdlib.h> #include<math.h> #include<algorithm> #include<iostream> #include<vector> #include<queue> using namespace std; typedef long long LL; #define N 10010001 #define ESP 1e-8 #define INF 0x3f3f3f3f #define memset(a,b) memset(a,b,sizeof(a)) LL prime[1000000], k; bool vis[N]; void Prime() { memset(vis, false); k = 0; for(int i=2; i<N; i++) { if(vis[i] == 0) { prime[k ++] = i; for(int j= i+i; j<N; j+=i) { vis[j] = 1; } } } } LL solve(LL n) { LL ans, sum; ans = 0; sum = 1; for(int i=0; prime[i] * prime[i] <= n; i++) { if(n%prime[i] == 0) { ans=0; while(n%prime[i] == 0) { ans ++; n /= prime[i]; } sum *= (2*ans+1); } } if(n>1) sum *= (2*1 + 1); return sum; } int main() { int T, t=1; LL n; Prime(); scanf("%d", &T); while(T --) { LL n; scanf("%lld", &n); LL sum = solve(n); printf("Case %d: %lld\n", t++, sum/2+1); } return 0; }