题解 P5436 【【XR-2】缘分】

StudyingFather

2019-06-29 20:50:51

Solution

一道非常不错的签到题。 首先,$ \operatorname{lcm}(a,b) = a * b / \gcd (a,b) $ 。要想让 $ \operatorname{lcm}(a,b) $ 尽可能大,当然要让 $ \gcd (a,b) $ 尽可能小。所以我们要取两个互质的整数 $ a,b $ 。 怎样让 $ a * b $ 尽可能大呢?当然是让两个数都尽可能大。于是我们的方案就呼之欲出了:我们取 $ n $ 和 $ n-1 $ 两个数字。 特别地,当 $ n=1 $ 时,我们取的两个整数都是 $ 1 $ ,答案也是 $ 1 $ 。 ```cpp #include <iostream> using namespace std; int main() { int t; cin>>t; while(t--) { long long x; cin>>x; if(x==1)cout<<1<<endl; else cout<<x*(x-1)<<endl; } return 0; } ```