一道数学题。
题目传送门。
Part 1 暴力
考虑枚举。
不妨假设 ,然后直接枚举 即可,由此你可以获得 分的好成绩。
代码如下:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){
int n;
cin>>n;
for(int j=1;j<=1000;j++){
for(int k=1;k<=1000;k++){
if(1+j*k/__gcd(j,k)==n+1+j+k){
cout<<1<<" "<<j<<" "<<k<<'\n';
return ;
}
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--) solve();
return 0;
}Part 2 正解
我们可以对所给式子进行移项。
而由于
因为
所以可以得出构造方案。
且
由一些尝试,可以得出,在 很小的时候,即可得出答案。
Part 3 完整代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){
int a;
cin>>a;
for(int b=1;;b++){
if((a+b-__gcd(a,b))%5==0){
cout<<b<<" "<<(a+b-__gcd(a,b))*3ll/5<<" "<<(a+b-__gcd(a,b))*4ll/5<<"\n";
return ;
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--) solve();
return 0;//完结撒花
}
/*
a+b+c+d=gcd(a,b)+lcm(c,d);
a+b-gcd(a,b)=lcm(c,d)-c-d
lcm(3k,4k)=12k;
3k+4k+5k=12k
5|a+b-gcd(a,b)
c=3/5*(a+b-gcd(a,b))
d=4/5*(a+b-gcd(a,b))
*/