結果

問題 No.648  お や す み 
ユーザー GrenacheGrenache
提出日時 2018-02-09 22:42:20
言語 Java
(openjdk 23)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 1,076 bytes
コンパイル時間 3,580 ms
コンパイル使用メモリ 78,212 KB
実行使用メモリ 54,416 KB
最終ジャッジ日時 2024-09-13 20:59:49
合計ジャッジ時間 16,778 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 84
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.math.*;
import java.util.*;


public class Main_yukicoder648 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		long n = sc.nextLong();

		BigInteger d = BigInteger.ONE.add(BigInteger.valueOf(8).multiply(BigInteger.valueOf(n)));
		long l = 0;
		long r = 1_000_000_000_000_000_000L;
		while (r - l > 1) {
			long mid = l + (r - l) / 2;
			BigInteger x2 = BigInteger.valueOf(mid).multiply(BigInteger.valueOf(mid));
			if (x2.compareTo(d) >= 0) {
//			if (data[mid] > value) {
				r = mid;
			} else {
				l = mid;
			}
		}

		if (BigInteger.valueOf(r).multiply(BigInteger.valueOf(r)).compareTo(d) == 0) {
			pr.println("YES");
			pr.println((r - 1) / 2);
		} else {
			pr.println("NO");
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0