結果

問題 No.781 円周上の格子点の数え上げ
ユーザー ats5515ats5515
提出日時 2019-01-11 22:05:08
言語 C++11
(gcc 8.5.0)
結果
AC  
実行時間 975 ms / 2,000 ms
コード長 1,397 bytes
コンパイル時間 1,007 ms
使用メモリ 237,508 KB
最終ジャッジ日時 2023-01-06 12:11:57
合計ジャッジ時間 17,047 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 607 ms
237,304 KB
testcase_01 AC 582 ms
237,508 KB
testcase_02 AC 574 ms
237,392 KB
testcase_03 AC 583 ms
237,440 KB
testcase_04 AC 594 ms
237,452 KB
testcase_05 AC 582 ms
237,508 KB
testcase_06 AC 575 ms
237,332 KB
testcase_07 AC 586 ms
237,448 KB
testcase_08 AC 584 ms
237,332 KB
testcase_09 AC 585 ms
237,452 KB
testcase_10 AC 582 ms
237,380 KB
testcase_11 AC 578 ms
237,336 KB
testcase_12 AC 875 ms
237,508 KB
testcase_13 AC 975 ms
237,400 KB
testcase_14 AC 666 ms
237,496 KB
testcase_15 AC 580 ms
237,500 KB
testcase_16 AC 682 ms
237,336 KB
testcase_17 AC 834 ms
237,312 KB
testcase_18 AC 576 ms
237,400 KB
testcase_19 AC 659 ms
237,508 KB
testcase_20 AC 577 ms
237,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
vector<int> p(10000003, 0);
vector<int> dp(10000003, -1);
int solve(int N) {
	if (dp[N] == -1) {
		int t = N;
		bool ok = false;
		int div = p[N];
		if (div > 0) {
			if (t % div == 0) {
				int c = 1;
				t /= div;
				while (t % div == 0) {
					t /= div;
					c++;
				}
				if (div % 4 == 3 && c % 2 == 1) {
					dp[N] = 0;
				}
				else if (div % 4 == 1) {
					dp[N] = (c + 1) * solve(t);
				}
				else {
					dp[N] = solve(t);
				}
			}
		}
		else {
			if (t % 4 == 3) {
				dp[N] = 0;
			}
			else if (t % 4 == 1) {
				dp[N] = 2;
			}

		}

	}
	return dp[N];
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int X, Y;
	cin >> X >> Y;
	int res = 0;
	int n = 10000001;
	dp[0] = 0;
	dp[1] = 1;
	dp[2] = 1;

	{
		vector<int> primes(n);
		for (int i = 2; i < n; ++i)
			primes[i] = i;

		for (int i = 2; i*i < n; ++i) {
			
			if (primes[i]) {
				for (int j = i * i; j < n; j += i) {
					primes[j] = 0;
					p[j] = i;
				}

			}
		}
	}


	/*for (int i = 2; i <= 20; i++) {
		cerr << i << " " << p[i] << endl;
	}*/
	int c;
	for (int i = X; i <= Y; i++) {

		int ans = solve(i);
		res = max(res, 4 * ans);
	}
	cout << res << endl;
}
0