結果

問題 No.732 3PrimeCounting
ユーザー claw88claw88
提出日時 2018-09-20 11:43:50
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 3,141 bytes
コンパイル時間 838 ms
コンパイル使用メモリ 112,836 KB
実行使用メモリ 27,540 KB
最終ジャッジ日時 2024-07-18 08:30:24
合計ジャッジ時間 36,288 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
23,832 KB
testcase_01 AC 21 ms
23,964 KB
testcase_02 AC 22 ms
23,836 KB
testcase_03 AC 21 ms
25,876 KB
testcase_04 AC 21 ms
26,052 KB
testcase_05 AC 20 ms
23,968 KB
testcase_06 AC 22 ms
26,172 KB
testcase_07 AC 22 ms
26,052 KB
testcase_08 AC 23 ms
25,924 KB
testcase_09 AC 23 ms
23,964 KB
testcase_10 AC 21 ms
23,728 KB
testcase_11 AC 21 ms
23,976 KB
testcase_12 AC 21 ms
23,980 KB
testcase_13 AC 21 ms
21,816 KB
testcase_14 AC 22 ms
23,752 KB
testcase_15 AC 22 ms
23,832 KB
testcase_16 AC 22 ms
26,048 KB
testcase_17 AC 21 ms
21,936 KB
testcase_18 AC 21 ms
24,000 KB
testcase_19 AC 22 ms
23,876 KB
testcase_20 AC 23 ms
24,028 KB
testcase_21 AC 27 ms
25,984 KB
testcase_22 AC 27 ms
24,108 KB
testcase_23 AC 24 ms
23,848 KB
testcase_24 AC 22 ms
23,980 KB
testcase_25 AC 34 ms
23,768 KB
testcase_26 AC 28 ms
23,860 KB
testcase_27 AC 24 ms
26,088 KB
testcase_28 AC 22 ms
23,836 KB
testcase_29 AC 23 ms
21,936 KB
testcase_30 AC 25 ms
24,236 KB
testcase_31 AC 26 ms
23,836 KB
testcase_32 AC 30 ms
26,044 KB
testcase_33 AC 29 ms
24,108 KB
testcase_34 AC 30 ms
23,984 KB
testcase_35 AC 28 ms
23,848 KB
testcase_36 AC 27 ms
26,020 KB
testcase_37 AC 22 ms
23,980 KB
testcase_38 AC 21 ms
23,852 KB
testcase_39 AC 28 ms
23,720 KB
testcase_40 AC 29 ms
24,092 KB
testcase_41 AC 28 ms
25,872 KB
testcase_42 AC 27 ms
25,884 KB
testcase_43 AC 25 ms
25,980 KB
testcase_44 AC 25 ms
23,936 KB
testcase_45 AC 22 ms
26,216 KB
testcase_46 AC 23 ms
23,840 KB
testcase_47 AC 24 ms
24,060 KB
testcase_48 AC 37 ms
24,180 KB
testcase_49 AC 37 ms
25,948 KB
testcase_50 AC 28 ms
23,964 KB
testcase_51 AC 26 ms
23,968 KB
testcase_52 AC 23 ms
26,144 KB
testcase_53 AC 70 ms
26,016 KB
testcase_54 AC 1,031 ms
26,320 KB
testcase_55 AC 1,028 ms
24,468 KB
testcase_56 AC 1,046 ms
26,192 KB
testcase_57 AC 196 ms
23,988 KB
testcase_58 AC 201 ms
23,848 KB
testcase_59 AC 79 ms
23,984 KB
testcase_60 AC 288 ms
26,020 KB
testcase_61 AC 291 ms
24,108 KB
testcase_62 AC 1,358 ms
26,628 KB
testcase_63 AC 561 ms
24,292 KB
testcase_64 AC 391 ms
24,480 KB
testcase_65 AC 405 ms
24,244 KB
testcase_66 AC 24 ms
22,068 KB
testcase_67 AC 23 ms
21,812 KB
testcase_68 AC 1,175 ms
24,216 KB
testcase_69 AC 1,160 ms
22,192 KB
testcase_70 AC 1,042 ms
24,472 KB
testcase_71 AC 1,064 ms
26,452 KB
testcase_72 AC 520 ms
24,476 KB
testcase_73 AC 2,217 ms
24,864 KB
testcase_74 AC 2,197 ms
26,996 KB
testcase_75 AC 34 ms
23,924 KB
testcase_76 AC 1,131 ms
22,324 KB
testcase_77 AC 207 ms
23,984 KB
testcase_78 AC 1,698 ms
24,732 KB
testcase_79 AC 1,173 ms
24,472 KB
testcase_80 AC 1,504 ms
24,624 KB
testcase_81 AC 1,046 ms
24,624 KB
testcase_82 AC 23 ms
24,156 KB
testcase_83 AC 209 ms
25,900 KB
testcase_84 AC 222 ms
23,848 KB
testcase_85 AC 861 ms
24,240 KB
testcase_86 AC 1,554 ms
24,604 KB
testcase_87 TLE -
testcase_88 TLE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 System.Text;
//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();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int N = cin.nextint;
        eratos(3 * N);
        var cnt = new long[3 * N + 1];
        long ans = 0;

        for (int i = 2; i < prime.Count; i++)
        {
            if (prime[i] > N) break;
            for (int j = 0; j < i - 1; j++)
            {
                cnt[prime[j] + prime[i - 1]]++;
            }

            foreach (var item in prime)
            {
                if(item - prime[i] >= 5)
                {
                    ans += cnt[item - prime[i]];
                }
            }
        }
        WriteLine(ans);
    }


    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;
            }
        }
    }
}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return 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 { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}
0