Codeforces 194B.Square

就叫暱稱吧發表於2020-10-27

1 題目描述(題目連結

在這裡插入圖片描述

2 題解

  輸入是 n n n,那麼結果是:
l c m ( 4 ∗ n , n + 1 ) n + 1 + 1 \cfrac{lcm(4*n, n+1)}{n+1} + 1 n+1lcm(4n,n+1)+1
即:
4 ∗ n g c d ( 4 ∗ n , n + 1 ) + 1 \cfrac{4*n}{gcd(4*n, n+1)} + 1 gcd(4n,n+1)4n+1

from math import gcd

n = int(input())
arr = input().split()
res = [4*int(i)//gcd(4*int(i), int(i) + 1) + 1 for i in arr]
for i in res:
    print(i)

相關文章