https://www.nowcoder.com/acm/contest/143/G
给出一个 c c ,给出一个取值范围。在范围中取两个数 a,b a , b 使得 gcd(a,b)=c g c d ( a , b ) = c ,最大化 a∗b a ∗ b 。
答案相当于是 c∗c∗x∗y c ∗ c ∗ x ∗ y 其中 x,y x , y 互质,那么最好的办法就是两者相差为 1 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;
}