Bài toán. Cho số nguyên dương n. Tính tổng 2022 + 2 + 4 + 6 + … + 2n. Ví dụ:
TONG.INP |
TONG.OUT |
20 |
2442 |
Code tham khảo:
fin = open("TONG.INP","r")
fout = open("TONG.OUT","w")
m = fin.readline()
n = int(m)
tong = 2022
for i in range(1, 2*n+1):
if i % 2 == 0:
tong += i
fout.write(str(tong))
fin.close
fout.close
Very interesting info!Perfect just what I was looking for!Raise your business