codeforces LCM Challenge

题目:http://codeforces.com/contest/235/problem/A

当给的 n 是奇数时,则是 n * (n - 1) * (n - 2),当是偶数时,则要从 n 往前枚举三个数,求出他们的最小公倍数,感觉最多不会枚举超过10个吧

View Code
 1 ll gcd(ll a,ll b)
 2 {
 3     if(!b) return a;
 4     else return gcd(b,a % b);
 5 }
 6 ll lcm(ll a,ll b)
 7 {
 8     //cout<<"((((\n";
 9     return a / gcd(a,b) * b;
10 }
11 int main()
12 {
13     ll x;
14     ll i,j,k;
15     //freopen("data.txt","r",stdin);
16     while(cin>>x)
17 
18     {
19         if(x <= 2)
20         {
21             cout<<x<<endl;
22             continue;
23         }
24         if(x % 2)
25         {
26             cout<<(x) * (x - 1) * (x - 2)<<endl;
27             continue;
28         }
29         ll maxx = -1;
30         for(i = x; i >= x - 10; i--)
31         {
32             for(j = i - 1; j >= x - 10; j--)
33             {
34                 for(k = j - 1; k >= x - 10; k--)
35                 {
36                     if(i < 0 || j < 0 || k < 0) continue;
37                     maxx = Max(maxx,lcm(lcm(i,j),k));
38                 }
39             }
40         }
41         cout<<maxx<<endl;
42 
43     }
44     return 0;
45 }

 

posted @ 2012-10-24 19:49  AC_Girl  阅读(320)  评论(0编辑  收藏  举报