結果

問題 No.781 円周上の格子点の数え上げ
ユーザー treeonetreeone
提出日時 2019-01-11 22:38:47
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,368 ms / 2,000 ms
コード長 1,469 bytes
コンパイル時間 2,415 ms
コンパイル使用メモリ 198,400 KB
実行使用メモリ 96,760 KB
最終ジャッジ日時 2023-08-20 11:37:25
合計ジャッジ時間 8,603 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,460 KB
testcase_01 AC 2 ms
7,512 KB
testcase_02 AC 2 ms
7,420 KB
testcase_03 AC 2 ms
7,432 KB
testcase_04 AC 2 ms
7,644 KB
testcase_05 AC 2 ms
7,468 KB
testcase_06 AC 3 ms
7,820 KB
testcase_07 AC 5 ms
8,364 KB
testcase_08 AC 673 ms
96,520 KB
testcase_09 AC 669 ms
96,584 KB
testcase_10 AC 4 ms
7,592 KB
testcase_11 AC 7 ms
7,856 KB
testcase_12 AC 1,062 ms
96,760 KB
testcase_13 AC 1,368 ms
96,644 KB
testcase_14 AC 22 ms
15,600 KB
testcase_15 AC 3 ms
7,704 KB
testcase_16 AC 3 ms
7,736 KB
testcase_17 AC 756 ms
62,756 KB
testcase_18 AC 365 ms
62,748 KB
testcase_19 AC 372 ms
66,008 KB
testcase_20 AC 380 ms
66,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;
const int MAX_N = 10000010;
int prime[MAX_N];
bool is_prime[MAX_N + 1];
int pf[MAX_N];
int sieve(int n){
    int p = 0;
    for(int i = 0; i <= n; i++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for(int i = 2; i <= n; i++){
        if(is_prime[i]){
            prime[p++] = i;
            for(int j = 2*i; j <= n; j += i){
                is_prime[j] = false;
                pf[j] = i;
            }
        }
    }
    return p;
}

int prime_factor(int n){
    int res = 1;
    while(n != 1){
        int now = pf[n];
        if(now == 0){
            if(n % 4 == 1) res *= 2;
            else if(n != 2) res = 0;
            break;
        }
        int cnt = 0;
        while(n % now == 0){
            n /= now;
            cnt++;
        }
        if(now % 4 == 1) res *= cnt + 1;
        else if(now % 4 == 3 && cnt % 2) return 0;
    }
    return res * 4;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, y;
    cin >> x >> y;
    sieve(y + 1);
    int ans = 0;
    for(int i = x; i <= y; i++){
        ans = max(ans, prime_factor(i));
    }
    cout << ans << endl;
}
0