题目链接

题意 : 中文题不详述。

思路 : 由N%Mi=(Mi-a)可得(N+a)%Mi=0;要取最小的N即找Mi的最小公倍数即可。

 1 //1788
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <iostream>
 6 #define LL long long
 7 
 8 using namespace std ;
 9 
10 LL gcd(LL x,LL y)
11 {
12     return y == 0 ? x : gcd(y,x%y) ;
13 }
14 int main()
15 {
16     int I,a ;
17     while(~scanf("%d %d",&I,&a))
18     {
19         if(I == 0 && a == 0) break ;
20         int x ;
21         LL ans = 1;
22         while(I--)
23         {
24             scanf("%d",&x) ;
25             ans = (ans * x)/gcd(ans,x) ;
26         }
27         printf("%I64d\n",ans-a) ;
28     }
29     return 0 ;
30 }
View Code

相关文章:

  • 2021-10-24
  • 2021-06-08
  • 2021-10-06
  • 2021-07-12
  • 2021-09-02
  • 2021-08-01
  • 2022-12-23
猜你喜欢
  • 2021-07-23
  • 2021-11-20
  • 2021-05-25
  • 2022-12-23
  • 2021-07-18
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案