結果

問題 No.1946 ロッカーの問題
ユーザー bluemegane
提出日時 2022-05-21 07:37:18
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 872 ms / 3,000 ms
コード長 1,113 bytes
コンパイル時間 3,650 ms
コンパイル使用メモリ 103,552 KB
実行使用メモリ 38,400 KB
最終ジャッジ日時 2024-09-20 11:07:58
合計ジャッジ時間 7,943 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using static System.Math;
using System.Collections.Generic;
using System;

public class Hello
{
    static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        if (m == 0) { Console.WriteLine(n); goto exit; }
        line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        getAns(n, a);
    exit:;
    }
    static void getAns(int n, int[] a)
    {
        var f = new bool[n + 1];
        foreach (var x in a) f[x] = true;
        var count = 0;
        for (int i = n; i >= 1; i--)
        {
            if (!f[i]) { count++; continue; }
            foreach (var x in getDiv(i)) f[x] = f[x] ? false : true;
        }
        Console.WriteLine(count);
    }
    static List<int> getDiv(int n)
    {
        var ans = new List<int>();
        for (int i = 1; i <= Sqrt(n); i++)
        {
            if (n % i == 0)
            {
                ans.Add(i);
                if (n != i * i) ans.Add(n / i);
            }
        }
        return ans;
    }
}
0