The Unsolvable Problem
给出n,求满足a+b=n,a和b最小公倍数的最大值是多少...
把n取半,看拆分的两半有木有公约数...
#include <cstdio>
#include <iostream>
using namespace std;
int gcd(int a,int b)
{
return (b==0?a:gcd(b,a%b));
}
int main()
{
int n,T;
scanf("%d",&T);
while (T--)
{
scanf("%lld",&n);
__int64 k=n/2;
__int64 s;
while (gcd(k,(n-k))!=1) k--;
s=k*(n-k);
printf("%I64d\n",s);
}
return 0;
}
本文介绍了一种通过编程解决数学问题的方法:给定一个整数n,寻找两个正整数a和b,使得a+b等于n且a和b的最小公倍数(LCM)达到最大值。该问题通过逐步减小n/2的值直至找到两个数没有公约数来解决。
1634

被折叠的 条评论
为什么被折叠?



