結果

問題 No.1047 Zero (Novice)
ユーザー joybeeeejoybeeee
提出日時 2020-05-12 15:55:50
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 430 bytes
コンパイル時間 2,196 ms
コンパイル使用メモリ 72,284 KB
実行使用メモリ 228,412 KB
最終ジャッジ日時 2023-10-11 15:10:53
合計ジャッジ時間 7,158 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
62,632 KB
testcase_01 AC 125 ms
56,180 KB
testcase_02 AC 126 ms
55,448 KB
testcase_03 AC 122 ms
54,340 KB
testcase_04 AC 123 ms
54,212 KB
testcase_05 AC 122 ms
55,928 KB
testcase_06 AC 122 ms
55,716 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt(); 
        int n = 0;
        Set<Integer> seen = new HashSet<>();
        while(!seen.contains(n)) {
        	seen.add(n);
        	n = a *  n + b;
        }

        System.out.println(n == 0 ? seen.size() : -1);	
    }
}
0