AOJ 2197 "Sum of Consecutive Integers"
問題:http://rose.u-aizu.ac.jp/onlinejudge/ProblemSet/description.jsp?id=2197&lang=jp
テキトー.
提出コードの後のコード(216B)
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);for(int i,j,t,b;(t=s.nextInt())>0;System.out.println(b))for(b=i=0;i++<t;)for(j=1;j++<t-i;)b+=j*(2*i+j-1)==t*2?1:0;}}
整形コード
import java.util.*; class Main { public static void main(String[] z) { Scanner s = new Scanner(System.in); for (int i, j, t, b; (t = s.nextInt()) > 0; System.out.println(b)) for (b = i = 0; i++ < t;) for (j = 1; j++ < t - i;) b += j * (2 * i + j - 1) == t * 2 ? 1 : 0; } }