結果

問題 No.648  お や す み 
ユーザー denderaKawazu
提出日時 2018-02-09 23:25:45
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,253 bytes
コンパイル時間 2,390 ms
コンパイル使用メモリ 74,912 KB
実行使用メモリ 56,448 KB
最終ジャッジ日時 2024-10-09 02:33:44
合計ジャッジ時間 14,562 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 69 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long n = in.nextLong();
            long maxN = n;
            long minN = 0;

            while (minN <= maxN) {
                long cn = (maxN + minN) / 2;
                long sum = cn * (cn + 1) / 2;
                if (sum == n) {
                    out.println("YES");
                    out.println(cn);
                    return;
                } else if (sum > n) {
                    maxN = cn - 1;
                } else if (sum < n) {
                    minN = cn + 1;
                }
            }
            out.println("NO");
        }

    }
}

0