题意:一个正整数K,给出K Mod 一些质数的结果,求符合条件的最小的K。例如,K % 2 = 1, K % 3 = 2, K % 5 = 3。符合条件的最小的K = 23。
链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1079
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn = 20;
int a[maxn],b[maxn];
int main()
{
int t;
while(cin >> t)
{
for(int i=0; i<t; i++)
scanf("%d%d",&a[i],&b[i]);
int cnt=1,s=0;
for(int i=0; i<t; i++)
{
while(1)
{
if(s%a[i] == b[i])
{
cnt*=a[i];
break;
}
s += cnt;
}
}
printf("%d\n",s);
}
return 0;
}