AtCoder Beginner Contest 152 E.Flatten
Problem Statement
Given are
positive integers
Consider positive integers
that satisfy the following condition.
Condition: For any
such that
holds.
Find the minimum possible value of
for such
Since the answer can be enormous, print the sum modulo
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the minimum possible value of
for
that satisfy the condition, modulo (
).
Sample Input 1
3
2 3 4
Sample Output 1
13
Sample Input 2
5
12 12 12 12 12
Sample Output 2
5
Sample Input 3
3
1000000 999999 999998
Sample Output 3
996989508
自学了一下Markdown,终于能展示题面啦嘻嘻(●’◡’●)
这道题python过的,技巧就是内置的sum函数,否则会超时,吐槽一下python的强大,直接暴力:
def gcd(a,b):
if b==0:
return a
else:
return gcd(b,a%b)
n=int(input())
mod=1000000007
s=[int(i) for i in input().split()]
ans=1
for i in s:
ans*=i//gcd(ans,i)
print(sum(ans//i for i in s)%mod)