結果
問題 | No.8079 アルベド |
ユーザー |
|
提出日時 | 2021-04-02 10:25:07 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 89 ms / 2,000 ms |
コード長 | 858 bytes |
コンパイル時間 | 4,659 ms |
コンパイル使用メモリ | 107,392 KB |
実行使用メモリ | 24,448 KB |
最終ジャッジ日時 | 2024-12-23 03:05:14 |
合計ジャッジ時間 | 3,466 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;using System.Collections.Generic;using System.Linq;class G{static void Main() => Console.WriteLine(Solve());static object Solve(){var t = int.Parse(Console.ReadLine());var ns = Array.ConvertAll(new bool[t], _ => int.Parse(Console.ReadLine()));var ps = GetPrimes(ns.Max());return string.Join("\n", ns.Select(GetCount));int GetCount(int n){return Last(-1, ps.Length - 1, x => ps[x] <= n) + 1;}}static int[] GetPrimes(int n){var b = new bool[n + 1];for (int p = 2; p * p <= n; ++p) if (!b[p]) for (int x = p * p; x <= n; x += p) b[x] = true;var r = new List<int>();for (int x = 2; x <= n; ++x) if (!b[x]) r.Add(x);return r.ToArray();}static int Last(int l, int r, Func<int, bool> f){int m;while (l < r) if (f(m = r - (r - l - 1) / 2)) l = m; else r = m - 1;return l;}}