标签:
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2415 Accepted Submission(s): 997
#include <stdio.h> #include <string.h> #include <algorithm> #include <iostream> #include <math.h> using namespace std; typedef long long LL; LL gcd(LL a,LL b){ return b==0?a:gcd(b,a%b); } LL lcm(LL a,LL b){ return a/gcd(a,b)*b; } int main() { int n; LL a; while(scanf("%d%lld",&n,&a)!=EOF,n&&a){ LL ans = 1,num; for(int i=0;i<n;i++){ scanf("%lld",&num); ans = lcm(ans,num); } printf("%lld\n",ans-a); } return 0; }
标签:
原文地址:http://www.cnblogs.com/liyinggang/p/5533763.html