結果

問題 No.1946 ロッカーの問題
ユーザー tentententen
提出日時 2023-08-08 12:57:30
言語 Java21
(openjdk 21)
結果
AC  
実行時間 772 ms / 3,000 ms
コード長 2,081 bytes
コンパイル時間 2,640 ms
コンパイル使用メモリ 84,776 KB
実行使用メモリ 56,980 KB
最終ジャッジ日時 2024-04-26 05:48:58
合計ジャッジ時間 7,988 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
50,452 KB
testcase_01 AC 55 ms
50,388 KB
testcase_02 AC 58 ms
50,612 KB
testcase_03 AC 678 ms
56,980 KB
testcase_04 AC 55 ms
37,364 KB
testcase_05 AC 116 ms
39,956 KB
testcase_06 AC 133 ms
40,744 KB
testcase_07 AC 114 ms
39,984 KB
testcase_08 AC 321 ms
44,804 KB
testcase_09 AC 604 ms
46,884 KB
testcase_10 AC 535 ms
45,748 KB
testcase_11 AC 89 ms
39,236 KB
testcase_12 AC 220 ms
42,532 KB
testcase_13 AC 49 ms
37,340 KB
testcase_14 AC 50 ms
37,292 KB
testcase_15 AC 50 ms
37,212 KB
testcase_16 AC 50 ms
37,188 KB
testcase_17 AC 391 ms
44,924 KB
testcase_18 AC 772 ms
45,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        boolean[] opens = new boolean[n + 1];
        while (m-- > 0) {
            opens[sc.nextInt()] = true;
        }
        int ans = 0;
        for (int i = n; i >= 1; i--) {
            if (opens[i]) {
                for (int j = 1; j <= Math.sqrt(i); j++) {
                    if (i % j == 0) {
                        opens[j] ^= true;
                        if (j * j < i) {
                            opens[i / j] ^= true;
                        }
                    }
                }
            } else {
                ans++;
            }
        }
        System.out.println(ans);
    }
} 
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
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 int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0