Skip to content

Instantly share code, notes, and snippets.

@uchidama
Last active July 10, 2021 15:26
Show Gist options
  • Save uchidama/346ed9a1f65bd289e87aa96aff11eded to your computer and use it in GitHub Desktop.
Save uchidama/346ed9a1f65bd289e87aa96aff11eded to your computer and use it in GitHub Desktop.
AtCoder Beginner Contest 190 [ D - Staircase Sequences ] https://atcoder.jp/contests/abc190/tasks/abc190_d
'''
[問題]
https://atcoder.jp/contests/abc190/tasks/abc190_d
[解説]
https://atcoder.jp/contests/abc190/editorial/643
https://atcoder.jp/contests/abc190/submissions/19787117
https://manabitimes.jp/math/1120
等差数列の和の公式
初項が a,公差が d,項数が n
Sn = n/2*(2*a + (n-1)*d)
d = 1なので
Sn = n/2*(2*a + (n-1))
2*Sn = n*(2*a + (n-1))
なので、nは2*Snの正の約数になる
展開すると
2*Sn/n - n = 2*a-1
2*a-1は必ず奇数で、奇数かどうかで成立するかどうかが判定できる
nは約数なので、2*Snの約数を総当たりで求める。
nを仮決めすると2*a-1の値は2*Sn/n - nで求められる。
この値の奇遇を判定する。
'''
# 再帰上限の引き上げ
import sys
sys.setrecursionlimit(10 ** 6)
INF = 10 ** 18 + 7
def dbgout(*args):
#print(args)
iiiii = 0
Sn = int(input())
dbgout(Sn)
# Mの約数を全部求める
def div(M):
res = set()
i = 1
while (i*i < M):
if M%i==0:
res.add(i)
res.add(M//i)
i+=1
return res
yaku = div(2*Sn)
ans = 0
for n in yaku:
# 2a-1が奇数ならOK。2*Sn/n-n = 2a-1 なので
if (2*Sn/n - n)%2 == 1:
ans += 1
print(ans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment