题目传送门:B2133 我家的门牌号 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
我们设总门牌号之和为cnt,小明家门牌号为x,其他人门牌号之和为a(即cnt-x),得:
- a-2x=n
- a=cnt-x;
∴ n=cnt-3x
依据条件,直接暴力:
#include<cstdio>
long long int n,cnt;
int main(){
scanf("%lld",&n);
for(long long int i=1;;i++){
cnt+=i;
for(long long int j=1;j<=i;j++){
if((cnt-3*j)==n){
printf("%lld %lld",j,i);
return 0;
}
}
}
}
2022/6/22