Problem:


Problem A: Sum of Consecutive Integers

連続する整数の和

-->

あなたは数か月に渡る受験戦争を勝ち抜き，晴れてICPC大学に入学することができた．入学手続きの日，大学のキャンパス内では熱狂的なサークルの勧誘活動が行われており，あなたは大量のパンフレットを受け取って帰ってきた．部屋に戻ってきたあなたは受け取ったパンフレットの中から気になる一枚を見つけた．そのパンフレットは大学の広報部から渡されたものだった．

パンフレットには以下のような問題が記されていた．

和が N となるような，連続する2つ以上の正の整数の組み合わせは，何組存在するでしょうか？例えば， 9 は 2+3+4 と 4+5 の 2通りの組み合わせがあります．

この問題の答えが気になったあなたは，プログラムを書いてその答えを調べることにした．したがって，あなたの仕事は，入力として与えられる正の整数 N に対して，問題の答えを出力するプログラムを書くことである．

Input

入力はデータセットの並びである．各データセットはひとつの整数 N からなる一行である．ここで 1 ≤ N ≤ 1000 である．

入力の終りは，ひとつのゼロからなる一行で示される．

Output

出力は，入力の各データセットの表す正の整数に対する問題の答えを，入力データセットの順序通りに並べたものである．それ以外の文字が出力にあってはならない．

Sample Input

9
500
0

Output for the Sample Input

2
3



Sample input:
9
500
0


Sample output:
2
3

Submission status: Accepted

Solution code:
import math


def get_one_int()->int:
    one_int = int(input())
    return one_int

def make_divisors(num:int)->set:
    divisors = set()
    for i in range(1, math.floor(num ** 0.5) + 1):
        if num % i == 0:
            divisors.add(i)
            divisors.add(num // i)
    return divisors

def count_odd_num(num_set)->int:
    odd_num = 0
    for i in num_set:
        if i % 2 != 0:
            odd_num += 1
    return odd_num

if __name__ == "__main__":
    while True:
        given_num = get_one_int()
        if given_num == 0:
            break
        divisors = make_divisors(given_num)
        odd_num = count_odd_num(divisors)
        odd_num -= 1 # remove 1
        print(odd_num)

Submission status: Accepted

Solution code:
while 1:
    n = int(input())
    if n == 0:
        break
    count = 0
    for i in range(1,n):
        cnt = 0
        for j in range(i,n):
            cnt += j
            if cnt >= n:
                break
        if cnt == n:
            count += 1
    print(count)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    while 1:
        n = II()
        ans = 0
        if n == 0:
            break
        i = 1
        while i < n / 2:
            tmp = 0
            l = i
            while tmp < n:
                tmp += l
                l += 1
            if tmp == n:
                ans += 1
            i += 1
        print(ans)  

    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    R, C, K = LI()
    n = II()
    rc = LIR_(n)
    fldr = [0 for _ in range(R)]
    fldc = [0 for _ in range(C)]
    for r, c in rc:
        fldr[r] += 1
        fldc[c] += 1
    fldcs = fldc[::1]
    fldcs.sort()
    fldrs = fldr[::1]
    fldrs.sort()
    ans = 0
    dr = defaultdict(int)
    dc = defaultdict(int)
    for k in range(R):
        dr[fldr[k]] += 1
    for k in range(C):
        dc[fldc[k]] += 1
    for k in range(K+1):
        ans += dr[K - k] * dc[k]
    for r, c in rc:
        a = fldr[r] + fldc[c]
        if a == K:
            ans -= 1
        elif a == K + 1:
            ans += 1
    print(ans)
    return

#F
def F():
    n, m = LI()
    uvl = LIR_(m)
    dist = [[inf] * n for _ in range(n)]
    dist0 = defaultdict(int)
    full = []
    d = 0
    for u, v, l in uvl:
        if u == 0:
            dist0[v] = l + 1
            full.append(v)
            d += 1
        elif v == 0:
            dist0[u] = l + 1
            d += 1
            full.append(u)
        else:
            l += 1
            dist[u][v] = l
            dist[v][u] = l
    for i in range(n):
        dist[i][i] = 0
    for k in range(n):
        for i in range(n):
            for j in range(n):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    
    fulls = itertools.combinations(range(d), 2)
    ans = inf
    for a, b in fulls:
        a, b = full[a], full[b]
        tmp = dist0[a] + dist0[b] + dist[a][b]
        ans = min(ans, tmp)
    print(-1 if ans == inf else ans)
    return

#G
def G():
    s = S()
    s = s[::-1]
    M_count = s.count("M")
    M_lis = [0] * M_count
    M_count //= 2
    tmp = 0
    k = 0
    for i in range(len(s)):
        if s[i] == "+":
            tmp += 1
        elif s[i] == "-":
            tmp -= 1
        else:
            M_lis[k] = tmp
            k += 1
    M_lis.sort()
    print(-sum(M_lis[:M_count]) + sum(M_lis[M_count:]))


    return

#H
def H():
    def f(t):
        return a * t + b * math.sin(c * t * math.pi)
    a, b, c = LI()
    ok = 99 // a + 1
    ng = 0
    while 1:
        t = (ok + ng) / 2
        ft = f(t)
        if abs(ft - 100) <= 10 ** (-6):
            print(t)
            return
        if ft > 100:
            ok = t
        if ft < 100:
            ng = t
    return

#Solve
if __name__ == '__main__':
    A()

Submission status: Accepted

Solution code:
A=[]
counter=0
sum=0
while True:
    N=int(input())
    if N==0:
        for i in range(len(A)):
            print(A[i])
        break
    else:
        for i in range(1,N):
            j=i
            while sum<N:
                sum+=j
                j+=1
            if sum==N:
                counter+=1
            sum=0
        A.append(counter)
        counter=0

Submission status: Accepted

Solution code:
while True:
	n=int(input())
	ans=0
	if n==0:
		break
	for i in range(2,n):
		ave=n/i
		if ave==int(ave):
			if ave-i//2>0 and i%2!=0:
				ans+=1
		elif ave==int(ave)+0.5:
			if ave-i//2>0:
				ans+=1
	print(ans)

Submission status: Accepted

Solution code:
while (True):
  target = int(input())
  if target == 0:
    break
  answer = 0

  for i in range(target - 1):
    index = i + 2

    if (target - (0.5 * index * (index - 1))) % index == 0 and (target - (0.5 * index * (index - 1))) > 0:
      answer += 1


  print(answer)

Submission status: Accepted

Solution code:
N=int(input())
while N!=0:
  a=N
  ans=0
  for i in range(1,N):
    for k in range(i,N):
      a=a-k
      if a==0 and N!=k:
        ans+=1
      elif a<0:
        break
    a=N   
  print(ans)
  N=int(input())

Submission status: Accepted

Solution code:


while True:

    N = int(input())

    if N == 0:
        break

    ans = 0

    lis = [0]

    for i in range(1000):

        lis.append(lis[-1] + i+1)

    for i in range(1001):

        for j in range(i-1):

            if lis[i] - lis[j] == N:
                ans += 1

    print (ans)

Submission status: Accepted

Solution code:
def f(n):
    res = 0
    for i in range(1, 1000):
        m = n + i * (i - 1) // 2
        r = int((m * 2) ** 0.5)
        if r * (r + 1) // 2 == m and r > i:
            res += 1
            # print(i, m, r)
    return res

while 1:
    n = int(input())
    if n == 0:
        break
    print(f(n))

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    ans = 0
    start, end = 1, 3
    while end <= n:
        if sum(range(start, end)) < n:
            end += 1
        elif sum(range(start, end)) > n:
            start += 1
        elif sum(range(start, end)) == n:
            ans += 1
            end += 1
    print(ans)

Submission status: Accepted

Solution code:
while True:
	n = int(input())
	if n == 0: break
	ans = 0
	for i in range(1,n//2+2):
		sumnum = i
		if sumnum >= n:
			continue
		j = i+1
		while j <= n//2+1:
			sumnum += j
			j += 1
			if sumnum >= n:
				if sumnum == n:
					ans += 1
				break
	print(ans)

Submission status: Accepted

Solution code:
while True:
  n=int(input())
  if n==0:
    break
  count=0
  for i in range(1,n):
    goukei=0
    for j in range(i,n):
      goukei+=j
      #print(goukei)
      if goukei==n:
        count+=1
        break
      if goukei>n:
        break

  print(count)

Submission status: Accepted

Solution code:
while True:
  n = int(input())
  if n == 0:
     break
  else:
    cnt = 0
    for i in range(1, n // 2 + 1):
      sum = i
      for j in range(i + 1, n):
        sum += j
        if sum == n:
          cnt += 1
          break
        elif sum > n:
          break
    print(cnt)

Submission status: Accepted

Solution code:
# Sum of Consecutive Integers

ans = []

while True:
    n = int(input())

    if n == 0:
        break
    s = 0
    for i in range(1, n // 2 + 3):
        tmp = i
        for j in range(i + 1, n // 2 + 3):
            tmp += j
            if tmp == n:
                s += 1
                break
            elif tmp > n:
                break

    ans.append(s)

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
while 1:
    n=int(input())
    if n==0:break
    nk=1
    while nk*(nk+1)/2<n:nk+=1
    ans=0
    for i in range(2,nk+1):
        if i%2==1 and n%i==0 or i%2==0 and int(n/i-i/2+0.5)==n/i-i/2+1/2:ans+=1
    print(ans)

Submission status: Accepted

Solution code:
while 1:
    n=int(input())
    if not n:break
    c=0
    for i in range(3,n+1,2):
        if not n%i:c+=1
    print(c)

Submission status: Accepted

Solution code:
while 1:
    nums=[i for i in range(1,502)]
    l,r=0,2
    n=int(input())
    if(n==0):
        break
    ans=0
    while r<len(nums):
        if r-l<2:
            r+=1
            continue
        if sum(nums[l:r])==n:
            ans+=1
            l+=1
        elif sum(nums[l:r])>n:
            l+=1
        else:
            r+=1
    print(ans)

Submission status: Accepted

Solution code:
d = [0 for _ in range(1000 + 1)]
for i in range(1, 1000+1):
    j = i+1
    s = i
    while s <= 1000:
        s += j
        j += 1
        if s <= 1000:
            d[s] += 1

while True:
    N = int(raw_input())
    if N==0:
        break
    print d[N]

Submission status: Runtime Error

Solution code:
#include <cstdio>

int main(void){
  int n, i, j, cnt, tmp;
  while(scanf("%d", &n)){
    if(n == 0){
      break;
    }
    cnt = 0;
    for(i=1; i<n/2+1; i++){
      for(j=i; j<n; j++){
        tmp = (i + j) * (j - i + 1) / 2;
        if(tmp == n){
          cnt++;
          break;
        }
        if(tmp > n){
          break;
        }
      }
    }
    printf("%d\n", cnt);
  }
  return 0;
}

Submission status: Runtime Error

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    c = 0
    for i in range(2, 1001):
        for a in range(1, 1001):
            if i*a+(0.5*(i-1)*i) == n:
                c += 1
    print(c)

Submission status: Runtime Error

Solution code:
while True:
    try:
        n = int(input())
    except:
        break
    if n == 0:
        break
    c = 0
    for i in range(2, 1001):
        for a in range(1, 1001):
            if i*a+(0.5*(i-1)*i) == n:
                c += 1
    print(c)

Submission status: Runtime Error

Solution code:
while True:
    try:
        n = int(input())
    except ValueError:
        break
    if n == 0:
        break
    c = 0
    for i in range(2, 1001):
        for a in range(1, 1001):
            if i*a+(0.5*(i-1)*i) == n:
                c += 1
    print(c)

Submission status: Runtime Error

Solution code:
while 1:
    n=int(input())
    if not n:break    
    t=0
    cnt=0
    for i in range(2,n+1):
        o=n//i
        t+=(i-1) 
        p=n-(i*o-t)
        if o+p//i+1-i<1:break
        if p%i==0:cnt+=1
    print cnt