結果

問題 No.1019 最小格子三角形
ユーザー DEGwer3456DEGwer3456
提出日時 2020-04-03 21:57:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 909 ms / 2,000 ms
コード長 1,133 bytes
コンパイル時間 494 ms
コンパイル使用メモリ 52,404 KB
実行使用メモリ 59,624 KB
最終ジャッジ日時 2023-09-16 01:24:10
合計ジャッジ時間 18,662 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 382 ms
59,552 KB
testcase_01 AC 371 ms
59,580 KB
testcase_02 AC 374 ms
59,520 KB
testcase_03 AC 382 ms
59,560 KB
testcase_04 AC 381 ms
59,556 KB
testcase_05 AC 376 ms
59,568 KB
testcase_06 AC 384 ms
59,552 KB
testcase_07 AC 387 ms
59,560 KB
testcase_08 AC 385 ms
59,552 KB
testcase_09 AC 383 ms
59,560 KB
testcase_10 AC 383 ms
59,540 KB
testcase_11 AC 385 ms
59,552 KB
testcase_12 AC 396 ms
59,548 KB
testcase_13 AC 788 ms
59,576 KB
testcase_14 AC 890 ms
59,560 KB
testcase_15 AC 866 ms
59,556 KB
testcase_16 AC 778 ms
59,556 KB
testcase_17 AC 830 ms
59,580 KB
testcase_18 AC 786 ms
59,552 KB
testcase_19 AC 848 ms
59,556 KB
testcase_20 AC 794 ms
59,552 KB
testcase_21 AC 839 ms
59,552 KB
testcase_22 AC 899 ms
59,552 KB
testcase_23 AC 906 ms
59,616 KB
testcase_24 AC 897 ms
59,564 KB
testcase_25 AC 907 ms
59,624 KB
testcase_26 AC 909 ms
59,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll mod = 998244353;
vector<int>yk[1010101];
bool isco[1010101];
int main()
{
	for (int i = 2; i <= 1000000; i++)
	{
		if (isco[i])continue;
		yk[i].push_back(i);
		for (int j = i + i; j <= 1000000; j += i)isco[j] = true, yk[j].push_back(i);
	}
	ll num;
	scanf("%lld", &num);
	ll ans = 0;
	for (ll a = 1;; a++)
	{
		if (a*a > num)break;
		ll beg = 0, end = 1000000;
		for (;;)
		{
			if (beg == end)break;
			ll med = (beg + end + 1) / 2;
			if (a*a + med*med > num)end = med - 1;
			else beg = med;
		}
		ll b = beg;
		ll s1 = 0, s2 = 0;
		int t = yk[a].size();
		for (int p = 0; p < (1 << t); p++)
		{
			bool f = false;
			ll x = 1;
			for (int i = 0; i < t; i++)if (p&(1 << i))x *= yk[a][i], f = !f;
			ll z1 = b / x, z2 = z1*(z1 + 1) / 2 * x;
			if (!f)s1 = (s1 + z1) % mod, s2 = (s2 + z2) % mod;
			else s1 = (s1 + mod - z1) % mod, s2 = (s2 + mod - z2%mod) % mod;
		}
		//printf("%lld %lld %lld %lld  %lld           %d\n", a, b, s1, s2, s1*a + s2, t);
		ans = (ans + s1*a + s2) % mod;
	}
	printf("%lld\n", (ans * 24 + 8) % mod);
}
0