0
0

More than 1 year has passed since last update.

ABC103 C - Modulo Summation で笑ってしまった

Last updated at Posted at 2021-10-05

abc103_1.png
abc103_2.png
abc103_3.png

良くわからん。回答を見た。

思わず笑ってしまった。そんなんあり!?
いや、アリだ、きっと。。

ModuloSummation.py
N = int(input())
A = list(map(int,input().split()))

ans = 0

for i in range(N):
    ans += A[i]-1

print(ans)

再チャレンジ。過去のアプローチは丸忘れ状態。
A の最小公倍数-1 を m とすれば
良いと思った。

abc103c.py
N = int(input())
A = list(map(int,input().split()))
from math import gcd
x = (A[0]*A[0+1])//gcd(A[0],A[0+1])
for i in range(2,N):
    x = (x*A[i])//gcd(x,A[i])
#print(x)
ans = 0
for i in range(N):
    ans += (x-1)%A[i]
print(ans)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0