AtCoder Beginner Contest 152 E.Flatten

AtCoder Beginner Contest 152 E.Flatten

题目来源

Problem Statement

Given are N N positive integers A 1 , . . . , A N . A_1,...,A_N.
Consider positive integers B 1 , . . . , B N . B_1,...,B_N. that satisfy the following condition.
Condition: For any i , j i,j such that 1 i < j N , A i B i = A j B j 1≤i<j≤N , A_iB_i=A_jB_j holds.
Find the minimum possible value of B 1 + . . . + B N B_1+...+B_N for such B 1 , , B N . B_1,…,B_N.

Since the answer can be enormous, print the sum modulo ( 1 0 9 + 7 ) (10^9+7)

Constraints

  • 1 N 1 0 4 1\leq N \leq10^4
  • 1 A i 1 0 6 1 \leq A_i \leq 10^6
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:
N N
A 1 . . . A N A_1 ... A_N

Output

Print the minimum possible value of B 1 + . . . + B N B_1+...+B_N for B 1 , . . . , B N B_1,...,B_N
that satisfy the condition, modulo ( 1 0 9 + 7 10^9+7 ).

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)
发布了235 篇原创文章 · 获赞 13 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_43765333/article/details/104056477