一道数学题。
题目传送门。
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;
}