Codeforces Round #653 (Div. 3)A - Required Remainder
A - Required Remainder
题解:这个题应该是有很多种解法,这里提供一种比较暴力的方法,我们先把ans去取一个比较大的值,如果这个值大于n的话我们就让他减去一个x,因为减去一个x是对取模结果没有影响的,如果ans小于n的话,直接输出答案即可。
/*Keep on going Never give up*/
#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
const int maxn = 2e5+10;
const int MaxN = 0x3f3f3f3f;
const int MinN = 0xc0c0c00c;
typedef long long ll;
const int mod = 100000000;
using namespace std;
int main()
{
int t;
cin>>t;
while(t--){
int x,y,n;
cin>>x>>y>>n;
int ans,times=n/x;
while(true){
ans=times*x+y;
times--;
if(ans<=n){
cout<<ans<<endl;
break;
}
}
}
return 0;
}
题解 文章被收录于专栏
主要写一些题目的题解
查看4道真题和解析