結果

問題 No.843 Triple Primes
ユーザー claw88claw88
提出日時 2019-06-28 21:55:12
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 6,749 bytes
コンパイル時間 3,090 ms
コンパイル使用メモリ 114,772 KB
実行使用メモリ 24,192 KB
最終ジャッジ日時 2023-10-19 17:42:29
合計ジャッジ時間 3,684 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
24,192 KB
testcase_01 AC 34 ms
24,192 KB
testcase_02 AC 27 ms
24,192 KB
testcase_03 AC 27 ms
24,192 KB
testcase_04 AC 28 ms
24,192 KB
testcase_05 AC 28 ms
24,192 KB
testcase_06 AC 28 ms
24,192 KB
testcase_07 AC 33 ms
24,192 KB
testcase_08 AC 33 ms
24,192 KB
testcase_09 AC 33 ms
24,192 KB
testcase_10 AC 33 ms
24,192 KB
testcase_11 AC 33 ms
24,192 KB
testcase_12 AC 33 ms
24,192 KB
testcase_13 AC 33 ms
24,192 KB
testcase_14 AC 33 ms
24,192 KB
testcase_15 AC 33 ms
24,192 KB
testcase_16 AC 32 ms
24,192 KB
testcase_17 AC 28 ms
24,172 KB
testcase_18 AC 28 ms
24,192 KB
testcase_19 AC 29 ms
24,192 KB
testcase_20 AC 30 ms
24,192 KB
testcase_21 AC 29 ms
24,192 KB
testcase_22 AC 32 ms
24,192 KB
testcase_23 AC 32 ms
24,192 KB
testcase_24 AC 30 ms
24,192 KB
testcase_25 AC 30 ms
24,192 KB
testcase_26 AC 34 ms
24,192 KB
testcase_27 AC 29 ms
24,192 KB
testcase_28 AC 34 ms
24,192 KB
testcase_29 AC 29 ms
24,192 KB
testcase_30 AC 34 ms
24,192 KB
testcase_31 AC 29 ms
24,192 KB
testcase_32 AC 28 ms
24,192 KB
testcase_33 AC 30 ms
24,192 KB
testcase_34 AC 31 ms
24,192 KB
testcase_35 AC 34 ms
24,192 KB
testcase_36 AC 29 ms
24,192 KB
testcase_37 AC 33 ms
24,192 KB
testcase_38 AC 31 ms
24,192 KB
testcase_39 AC 33 ms
24,192 KB
testcase_40 AC 27 ms
24,192 KB
testcase_41 AC 27 ms
24,172 KB
testcase_42 AC 33 ms
24,192 KB
testcase_43 AC 33 ms
24,192 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using SB = System.Text.StringBuilder;
//using System.Threading.Tasks;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
using System.Numerics;
using static System.Math;
using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    readonly Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    readonly int dom = 998244353;
    bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; }

    struct data
    {
        public int x, y, z;
        public data(int x, int y, int z)
        {
            this.x = x;
            this.y = y;
            this.z = z;
        }
    }

    void solve()
    {
        int N = cin.nextint;
        eratos(N);

        var P = new[] { new data(2,2,2),
new data(2,7,3),
new data(7,2,3),
new data(2,23,5),
new data(23,2,5),
new data(2,47,7),
new data(47,2,7),
new data(2,167,13),
new data(167,2,13),
new data(2,359,19),
new data(359,2,19),
new data(2,839,29),
new data(839,2,29),
new data(2,1367,37),
new data(1367,2,37),
new data(2,1847,43),
new data(1847,2,43),
new data(2,2207,47),
new data(2207,2,47),
new data(2,3719,61),
new data(3719,2,61),
new data(2,5039,71),
new data(5039,2,71),
new data(2,7919,89),
new data(7919,2,89),
new data(2,10607,103),
new data(10607,2,103),
new data(2,11447,107),
new data(11447,2,107),
new data(2,16127,127),
new data(16127,2,127),
new data(2,17159,131),
new data(17159,2,131),
new data(2,19319,139),
new data(19319,2,139),
new data(2,29927,173),
new data(29927,2,173),
new data(2,36479,191),
new data(36479,2,191),
new data(2,44519,211),
new data(44519,2,211),
new data(2,49727,223),
new data(49727,2,223),
new data(2,54287,233),
new data(54287,2,233),
new data(2,57119,239),
new data(57119,2,239),
new data(2,66047,257),
new data(66047,2,257),
new data(2,85847,293),
new data(85847,2,293),
new data(2,97967,313),
new data(97967,2,313),
new data(2,113567,337),
new data(113567,2,337),
new data(2,128879,359),
new data(128879,2,359),
new data(2,177239,421),
new data(177239,2,421),
new data(2,196247,443),
new data(196247,2,443),
new data(2,201599,449),
new data(201599,2,449),
new data(2,218087,467),
new data(218087,2,467),
new data(2,241079,491),
new data(241079,2,491),
new data(2,273527,523),
new data(273527,2,523),
new data(2,292679,541),
new data(292679,2,541),
new data(2,323759,569),
new data(323759,2,569),
new data(2,344567,587),
new data(344567,2,587),
new data(2,368447,607),
new data(368447,2,607),
new data(2,426407,653),
new data(426407,2,653),
new data(2,458327,677),
new data(458327,2,677),};

        //int cnt = 0;
        //foreach (var r in prime)
        //{
        //    long L = (long)r * r;
        //    foreach (var p in prime)
        //    {
        //        if (p > L)
        //        {
        //            break;
        //        }
        //        if (L - p <= N && is_prime[L - p])
        //        {
        //            WriteLine($"new data({p},{L - p},{r}),");
        //        }
        //    }
        //}
        int cnt = 0;
        foreach (var item in P)
        {
            if (item.x <= N && item.y <= N && item.z <= N)
            {
                cnt++;
            }
        }
        WriteLine(cnt);
    }

    List<int> prime;
    bool[] is_prime;
    void eratos(int n)
    {
        prime = new List<int>();
        is_prime = new bool[n + 1];
        for (int i = 0; i <= n; i++) is_prime[i] = true;
        is_prime[0] = is_prime[1] = false;
        for (int i = 0; i <= n; i++)
        {
            if (is_prime[i])
            {
                prime.Add(i);
                for (int j = 2 * i; j <= n; j += i) is_prime[j] = false;
            }
        }
    }
    int[] P;
    void phi(int n)
    {
        P = new int[n + 1];
        for (int i = 0; i <= n; i++) P[i] = i;
        for (int i = 2; i <= n; i++)
        {
            if (is_prime[i])
            {
                P[i] -= P[i] / i;
                for (int j = 2 * i; j <= n; j += i) P[j] -= P[j] / i;
            }
        }
    }
}

static class Ex
{
    public static void join<T>(this IEnumerable<T> values, string sep = " ") => WriteLine(string.Join(sep, values));
    public static string concat<T>(this IEnumerable<T> values) => string.Concat(values);
    public static string reverse(this string s) { var t = s.ToCharArray(); Array.Reverse(t); return t.concat(); }

    public static int lower_bound<T>(this IList<T> arr, T val) where T : IComparable<T>
    {
        int low = 0, high = arr.Count;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (arr[mid].CompareTo(val) < 0) low = mid + 1;
            else high = mid;
        }
        return low;
    }
    public static int upper_bound<T>(this IList<T> arr, T val) where T : IComparable<T>
    {
        int low = 0, high = arr.Count;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (arr[mid].CompareTo(val) <= 0) low = mid + 1;
            else high = mid;
        }
        return low;
    }
}

class Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U>
{
    public T f; public U s;
    public Pair(T f, U s) { this.f = f; this.s = s; }
    public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s);
    public override string ToString() => $"{f} {s}";
}

class Scanner
{
    string[] s; int i;
    readonly char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan => ReadLine().Split();
    public int[] scanint => Array.ConvertAll(scan, int.Parse);
    public long[] scanlong => Array.ConvertAll(scan, long.Parse);
    public double[] scandouble => Array.ConvertAll(scan, double.Parse);
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint => int.Parse(next);
    public long nextlong => long.Parse(next);
    public double nextdouble => double.Parse(next);
}
0