結果

問題 No.413 +5,000,000pts
ユーザー 37zigen37zigen
提出日時 2016-06-06 21:19:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 543 ms / 5,000 ms
コード長 1,943 bytes
コンパイル時間 2,274 ms
コンパイル使用メモリ 78,900 KB
実行使用メモリ 63,216 KB
最終ジャッジ日時 2023-08-02 07:32:11
合計ジャッジ時間 3,759 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 543 ms
63,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.math.BigDecimal;

public class Main{
	public static void main(String[] args) {
		new Main().solve();
	}

	void solve() {
		int count = 0;
		for (long i = 1_000_000_000L; i >= 1; i--) {
			long d = i * (i + 1) - 1;
			if (d <= 1_000_000_000_000_000_000L) {
				while (!iscorrect(d)) {
					System.out.println(d);
					d--;
					count++;
					if (count == 100000)
						return;
				}
			}
		}
	}

	boolean iscorrect(long d) {
		if(d>1_000_000_000_000_000_000L){
			System.out.println("dが範囲外");
			System.exit(0);
		}
		long ans = calc(d);
		if (ans * ans + ans <= d && (ans + 1) * (ans + 1) + (ans + 1) > d) {
			return true;
		} else
			return false;
	}

	long calc(long d) {
		return (long) ((-1 + Math.sqrt(1 + 4 * d)) / 2.0);
	}

	double calc_ori(long d) {
		return (-1 + Math.sqrt(1 + 4 * d)) / 2.0;
	}

	BigDecimal calc_ori_ex(long d) {
		return BigDecimal.valueOf(-1).add(sqrt(BigDecimal.valueOf(4 * d + 1), 100)).divide(BigDecimal.valueOf(2));
	}

	void show(long d) {
		System.out.println("参加者の示すtの値" + calc(d));
		System.out.println("t*t+t           " + (calc(d) * calc(d) + calc(d)));
		System.out.println("(t+1)(t+1)+(t+1)" + ((calc(d) + 1) * (calc(d) + 1) + (calc(d) + 1)));
		System.out.println("d               " + d);
		System.out.println("二次方程式を解いた時のtの値(参加者の)" + calc_ori(d));
		System.out.println("二次方程式を解いた時のt(参加者の)でのt*t+t" + (calc_ori(d) * calc_ori(d) + calc_ori(d)));
		System.out.println("二次方程式を解いた時のtの値(精度を上げた)" + calc_ori_ex(d));
	}

	// scaleは桁数。
	public static BigDecimal sqrt(BigDecimal a, int scale) {
		BigDecimal x = a;
		for (int i = 0; i < 10000; i++) {
			// x=x-(x*x-a)/(2*x)
			x = x.subtract((x.multiply(x).subtract(a)).divide((x.multiply(BigDecimal.valueOf(2.0))), scale,
					BigDecimal.ROUND_HALF_EVEN));
		}
		return x;
	}
}
0