結果

問題 No.843 Triple Primes
ユーザー toyamatoyama
提出日時 2019-06-28 21:38:12
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1,014 ms / 2,000 ms
コード長 1,050 bytes
コンパイル時間 658 ms
コンパイル使用メモリ 29,180 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 17:33:43
合計ジャッジ時間 20,683 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1,014 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 684 ms
4,348 KB
testcase_08 AC 797 ms
4,348 KB
testcase_09 AC 1,005 ms
4,348 KB
testcase_10 AC 736 ms
4,348 KB
testcase_11 AC 872 ms
4,348 KB
testcase_12 AC 970 ms
4,348 KB
testcase_13 AC 916 ms
4,348 KB
testcase_14 AC 907 ms
4,348 KB
testcase_15 AC 700 ms
4,348 KB
testcase_16 AC 725 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 106 ms
4,348 KB
testcase_21 AC 38 ms
4,348 KB
testcase_22 AC 363 ms
4,348 KB
testcase_23 AC 389 ms
4,348 KB
testcase_24 AC 116 ms
4,348 KB
testcase_25 AC 74 ms
4,348 KB
testcase_26 AC 1,000 ms
4,348 KB
testcase_27 AC 8 ms
4,348 KB
testcase_28 AC 930 ms
4,348 KB
testcase_29 AC 131 ms
4,348 KB
testcase_30 AC 977 ms
4,348 KB
testcase_31 AC 16 ms
4,348 KB
testcase_32 AC 7 ms
4,348 KB
testcase_33 AC 153 ms
4,348 KB
testcase_34 AC 312 ms
4,348 KB
testcase_35 AC 1,008 ms
4,348 KB
testcase_36 AC 60 ms
4,348 KB
testcase_37 AC 636 ms
4,348 KB
testcase_38 AC 479 ms
4,348 KB
testcase_39 AC 940 ms
4,348 KB
testcase_40 AC 1 ms
4,348 KB
testcase_41 AC 1 ms
4,348 KB
testcase_42 AC 764 ms
4,348 KB
testcase_43 AC 864 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdbool.h>
typedef long long ll;

bool is_prime[500005];
ll list_prime[500005];

ll calc_prime(ll n);

int main()
{
    ll n;
    ll m;
    ll ans = 0;
    
    scanf("%lld", &n);

    m = calc_prime(n);

    for (ll i = 0; i < m; i++) {
        for (ll j = i; j < m; j++) {
            ll p = list_prime[i];
            ll r = list_prime[j];

            ll q = r * r - p;

            if (q >= 0 && q <= n && is_prime[q]) {
                if (i == j) {
                    ans++;
                }
                else {
                    ans += 2;
                }
            }
        }
    }

    printf("%lld\n", ans);

    return 0;
}

ll calc_prime(ll n)
{
    ll cnt = 0;
    
    for (ll i = 2; i <= n; i++) {
        is_prime[i] = true;
    }

    for (ll i = 2; i <= n; i++) {
        if (is_prime[i]) {
            list_prime[cnt] = i;
            cnt++;
            
            for (ll j = i + i; j <= n; j += i) {
                is_prime[j] = false;
            }
        }
    }

    return cnt;
}
0