結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 645 ms
237,264 KB
testcase_01 AC 647 ms
237,252 KB
testcase_02 AC 652 ms
237,440 KB
testcase_03 AC 640 ms
237,560 KB
testcase_04 AC 643 ms
237,388 KB
testcase_05 AC 635 ms
237,384 KB
testcase_06 AC 637 ms
237,456 KB
testcase_07 AC 638 ms
237,456 KB
testcase_08 AC 641 ms
237,512 KB
testcase_09 AC 633 ms
237,512 KB
testcase_10 AC 623 ms
237,536 KB
testcase_11 AC 667 ms
237,540 KB
testcase_12 AC 933 ms
237,384 KB
testcase_13 AC 1,039 ms
237,388 KB
testcase_14 AC 638 ms
237,436 KB
testcase_15 AC 640 ms
237,448 KB
testcase_16 AC 919 ms
237,448 KB
testcase_17 AC 860 ms
237,452 KB
testcase_18 AC 626 ms
237,572 KB
testcase_19 AC 639 ms
237,436 KB
testcase_20 AC 640 ms
237,392 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