Codeforces 194B.Square

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)
©️2020 CSDN 皮肤主题: Age of Ai 设计师:meimeiellie 返回首页