标签:style blog http io ar color os sp for
题意:
输入n,求至少两个正整数,使得这些数的最小公倍数为n且和最小。
分析:
这里有两个小技巧:
1 #include <cstdio> 2 #include <cmath> 3 4 typedef long long LL; 5 6 int main(void) 7 { 8 int n, kase = 0; 9 while(scanf("%d", &n) == 1 && n) 10 { 11 LL ans = 0; 12 int m = sqrt(n + 0.5); 13 int pcnt = 0; 14 15 if(n == 1) 16 { 17 printf("Case %d: 2\n", ++kase); 18 continue; 19 } 20 21 for(int i = 2; i <= m; ++i) 22 { 23 if(n % i == 0) 24 { 25 pcnt++; 26 int temp = 1; 27 while(n % i == 0) 28 { 29 n /= i; 30 temp *= i; 31 } 32 if(temp > 1) ans += temp; 33 } 34 } 35 if(n > 1) 36 { 37 pcnt++; 38 ans += n; 39 } 40 if(pcnt <= 1) ans++; 41 42 printf("Case %d: %lld\n", ++kase, ans); 43 44 } 45 46 return 0; 47 }
UVa 10791 (唯一分解) Minimum Sum LCM
标签:style blog http io ar color os sp for
原文地址:http://www.cnblogs.com/AOQNRMGYXLMV/p/4162188.html