牛客网暑期ACM多校训练营(第五场)G max【数学】

https://www.nowcoder.com/acm/contest/143/G

给出一个 c c ,给出一个取值范围[1,n]。在范围中取两个数 a,b a , b 使得 gcd(a,b)=c g c d ( a , b ) = c ,最大化 ab a ∗ b

答案相当于是 ccxy c ∗ c ∗ x ∗ y 其中 x,y x , y 互质,那么最好的办法就是两者相差为 1 1 x=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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值