1. 程式人生 > >牛客網暑期ACM多校訓練營(第五場)G max【數學】

牛客網暑期ACM多校訓練營(第五場)G max【數學】

給出一個c,給出一個取值範圍[1,n]。在範圍中取兩個數a,b使得 gcd(a,b)=c,最大化 ab

答案相當於是ccxy 其中 x,y 互質,那麼最好的辦法就是兩者相差為1x=y=1特判。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<iomanip>
using namespace std;
const int maxn = 1e5
+ 12; #define ll long long int int main() { ll c, n; ll a = -1, b = -1, ans = 0; scanf("%lld %lld", &c, &n); if (c > n) { puts("-1"); return 0; } a = ((n / c)*c); b = ((n / c - 1)*c); ans = a * b; if (n / c == 1) ans = c * c; printf("%lld\n", ans); return
0; }