結果

問題 No.648  お や す み 
ユーザー tentententen
提出日時 2022-10-06 14:34:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 1,431 bytes
コンパイル時間 1,712 ms
コンパイル使用メモリ 74,632 KB
実行使用メモリ 49,832 KB
最終ジャッジ日時 2023-08-31 00:55:46
合計ジャッジ時間 8,044 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
49,344 KB
testcase_01 AC 36 ms
49,524 KB
testcase_02 AC 36 ms
49,336 KB
testcase_03 AC 38 ms
49,388 KB
testcase_04 AC 37 ms
49,324 KB
testcase_05 AC 36 ms
49,484 KB
testcase_06 AC 37 ms
49,420 KB
testcase_07 AC 36 ms
49,324 KB
testcase_08 AC 36 ms
49,480 KB
testcase_09 AC 36 ms
49,832 KB
testcase_10 AC 37 ms
49,532 KB
testcase_11 AC 36 ms
49,688 KB
testcase_12 AC 36 ms
49,440 KB
testcase_13 AC 36 ms
49,460 KB
testcase_14 AC 35 ms
49,528 KB
testcase_15 AC 36 ms
49,388 KB
testcase_16 AC 35 ms
49,364 KB
testcase_17 AC 37 ms
49,276 KB
testcase_18 AC 37 ms
49,564 KB
testcase_19 AC 37 ms
49,528 KB
testcase_20 AC 36 ms
49,372 KB
testcase_21 AC 37 ms
49,308 KB
testcase_22 AC 36 ms
49,492 KB
testcase_23 AC 36 ms
49,528 KB
testcase_24 AC 37 ms
49,356 KB
testcase_25 AC 35 ms
49,404 KB
testcase_26 AC 38 ms
49,740 KB
testcase_27 AC 36 ms
49,604 KB
testcase_28 AC 36 ms
49,416 KB
testcase_29 AC 37 ms
49,556 KB
testcase_30 AC 37 ms
49,336 KB
testcase_31 AC 36 ms
49,380 KB
testcase_32 AC 37 ms
49,408 KB
testcase_33 AC 36 ms
49,272 KB
testcase_34 AC 36 ms
49,404 KB
testcase_35 AC 37 ms
49,320 KB
testcase_36 AC 36 ms
49,376 KB
testcase_37 AC 35 ms
49,500 KB
testcase_38 AC 36 ms
49,400 KB
testcase_39 AC 36 ms
49,560 KB
testcase_40 AC 36 ms
49,316 KB
testcase_41 AC 36 ms
49,484 KB
testcase_42 AC 36 ms
49,496 KB
testcase_43 AC 36 ms
49,356 KB
testcase_44 AC 35 ms
49,324 KB
testcase_45 AC 35 ms
49,284 KB
testcase_46 AC 36 ms
49,732 KB
testcase_47 AC 36 ms
49,376 KB
testcase_48 AC 36 ms
49,312 KB
testcase_49 AC 37 ms
49,384 KB
testcase_50 AC 36 ms
49,376 KB
testcase_51 AC 35 ms
49,492 KB
testcase_52 AC 37 ms
49,560 KB
testcase_53 AC 38 ms
49,388 KB
testcase_54 AC 37 ms
49,484 KB
testcase_55 AC 36 ms
49,392 KB
testcase_56 AC 36 ms
49,632 KB
testcase_57 AC 36 ms
49,316 KB
testcase_58 AC 38 ms
49,480 KB
testcase_59 AC 38 ms
49,380 KB
testcase_60 AC 35 ms
49,352 KB
testcase_61 AC 36 ms
49,368 KB
testcase_62 AC 36 ms
49,444 KB
testcase_63 AC 35 ms
49,476 KB
testcase_64 AC 36 ms
49,436 KB
testcase_65 AC 37 ms
49,308 KB
testcase_66 AC 37 ms
49,396 KB
testcase_67 AC 36 ms
49,488 KB
testcase_68 AC 37 ms
49,380 KB
testcase_69 AC 37 ms
49,556 KB
testcase_70 AC 37 ms
49,384 KB
testcase_71 AC 37 ms
49,384 KB
testcase_72 AC 36 ms
49,768 KB
testcase_73 AC 35 ms
49,828 KB
testcase_74 AC 36 ms
49,404 KB
testcase_75 AC 35 ms
49,432 KB
testcase_76 AC 37 ms
49,272 KB
testcase_77 AC 37 ms
49,484 KB
testcase_78 AC 36 ms
49,312 KB
testcase_79 AC 35 ms
49,472 KB
testcase_80 AC 37 ms
49,608 KB
testcase_81 AC 37 ms
49,312 KB
testcase_82 AC 36 ms
49,464 KB
testcase_83 AC 37 ms
49,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        long n = sc.nextLong();
        long left = 0;
        long right = Long.MAX_VALUE / 2;
        while (right - left > 1) {
            long m = (left + right) / 2;
            if (Long.MAX_VALUE / (m + 1) < m * 2 || m * (m + 1) / 2 > n) {
                right = m;
            } else {
                left = m;
            }
        }
        if (left * (left + 1) / 2 == n) {
            System.out.println("YES");
            System.out.println(left);
        } else {
            System.out.println("NO");
        }
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0