結果

問題 No.732 3PrimeCounting
ユーザー claw88claw88
提出日時 2018-09-20 11:54:30
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 1,888 ms / 3,000 ms
コード長 3,225 bytes
コンパイル時間 2,312 ms
コンパイル使用メモリ 108,244 KB
実行使用メモリ 24,024 KB
最終ジャッジ日時 2023-09-25 10:29:16
合計ジャッジ時間 29,896 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
20,704 KB
testcase_01 AC 58 ms
20,704 KB
testcase_02 AC 58 ms
22,712 KB
testcase_03 AC 59 ms
22,760 KB
testcase_04 AC 59 ms
22,728 KB
testcase_05 AC 58 ms
20,736 KB
testcase_06 AC 58 ms
18,840 KB
testcase_07 AC 58 ms
18,616 KB
testcase_08 AC 56 ms
20,804 KB
testcase_09 AC 57 ms
20,760 KB
testcase_10 AC 57 ms
20,736 KB
testcase_11 AC 58 ms
20,756 KB
testcase_12 AC 59 ms
22,732 KB
testcase_13 AC 58 ms
20,732 KB
testcase_14 AC 57 ms
20,772 KB
testcase_15 AC 58 ms
20,876 KB
testcase_16 AC 59 ms
22,732 KB
testcase_17 AC 58 ms
20,784 KB
testcase_18 AC 58 ms
20,716 KB
testcase_19 AC 58 ms
20,684 KB
testcase_20 AC 58 ms
20,732 KB
testcase_21 AC 60 ms
20,704 KB
testcase_22 AC 61 ms
22,772 KB
testcase_23 AC 59 ms
20,776 KB
testcase_24 AC 58 ms
20,620 KB
testcase_25 AC 67 ms
20,688 KB
testcase_26 AC 62 ms
22,768 KB
testcase_27 AC 60 ms
22,768 KB
testcase_28 AC 59 ms
22,728 KB
testcase_29 AC 60 ms
18,696 KB
testcase_30 AC 60 ms
18,712 KB
testcase_31 AC 61 ms
20,764 KB
testcase_32 AC 64 ms
20,764 KB
testcase_33 AC 63 ms
20,732 KB
testcase_34 AC 64 ms
20,708 KB
testcase_35 AC 61 ms
20,764 KB
testcase_36 AC 61 ms
20,808 KB
testcase_37 AC 59 ms
20,868 KB
testcase_38 AC 58 ms
20,692 KB
testcase_39 AC 62 ms
20,688 KB
testcase_40 AC 62 ms
22,808 KB
testcase_41 AC 62 ms
22,764 KB
testcase_42 AC 62 ms
22,728 KB
testcase_43 AC 59 ms
18,760 KB
testcase_44 AC 61 ms
22,764 KB
testcase_45 AC 59 ms
20,684 KB
testcase_46 AC 59 ms
22,736 KB
testcase_47 AC 59 ms
20,720 KB
testcase_48 AC 67 ms
20,720 KB
testcase_49 AC 67 ms
20,688 KB
testcase_50 AC 61 ms
20,684 KB
testcase_51 AC 60 ms
22,784 KB
testcase_52 AC 58 ms
18,688 KB
testcase_53 AC 88 ms
20,776 KB
testcase_54 AC 669 ms
21,304 KB
testcase_55 AC 667 ms
21,252 KB
testcase_56 AC 668 ms
23,280 KB
testcase_57 AC 160 ms
22,844 KB
testcase_58 AC 160 ms
20,676 KB
testcase_59 AC 91 ms
20,728 KB
testcase_60 AC 219 ms
20,760 KB
testcase_61 AC 219 ms
22,784 KB
testcase_62 AC 878 ms
21,608 KB
testcase_63 AC 379 ms
20,964 KB
testcase_64 AC 275 ms
22,832 KB
testcase_65 AC 272 ms
20,824 KB
testcase_66 AC 58 ms
22,756 KB
testcase_67 AC 57 ms
20,760 KB
testcase_68 AC 764 ms
21,284 KB
testcase_69 AC 761 ms
21,376 KB
testcase_70 AC 678 ms
21,228 KB
testcase_71 AC 686 ms
23,408 KB
testcase_72 AC 358 ms
20,960 KB
testcase_73 AC 1,387 ms
23,928 KB
testcase_74 AC 1,382 ms
24,024 KB
testcase_75 AC 65 ms
22,740 KB
testcase_76 AC 742 ms
21,328 KB
testcase_77 AC 174 ms
22,668 KB
testcase_78 AC 1,081 ms
21,684 KB
testcase_79 AC 773 ms
23,344 KB
testcase_80 AC 959 ms
21,648 KB
testcase_81 AC 688 ms
23,348 KB
testcase_82 AC 58 ms
20,764 KB
testcase_83 AC 166 ms
20,728 KB
testcase_84 AC 179 ms
20,736 KB
testcase_85 AC 574 ms
21,196 KB
testcase_86 AC 982 ms
23,736 KB
testcase_87 AC 1,881 ms
22,180 KB
testcase_88 AC 1,888 ms
22,428 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 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[2 * N];
        long ans = 0;

        int b = 3;
        foreach (var c in prime)
        {
            if (c > N) break;
            if (c < 5) continue;
            foreach (var a in prime)
            {
                if (a == b) break;
                cnt[a + b]++;
            }
            foreach (var abc in prime)
            {
                int ab = abc - c;
                if (5 <= ab && ab < cnt.Length)
                {
                    ans += cnt[ab];
                }
            }
            b = c;
        }

        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