提出 #17149149


ソースコード 拡げる

#include <bits/stdc++.h>

typedef long long int64;

const int N = 1e5;

int64 n;
int x, m, vis[N + 5];

int main() {
	scanf("%lld%d%d", &n, &x, &m);
	std::fill(vis, vis + m, -1);
	std::vector<int> vec, cir;
	vec.emplace_back(x);
	vis[x] = 0;
	for (; ; ) {
		x = (int64)x * x % m;
		if (vis[x] >= 0) {
			cir = std::vector<int>(vec.begin() + vis[x], vec.end());
			vec.erase(vec.begin() + vis[x], vec.end());
			break;
		}
		vis[x] = vec.size();
		vec.emplace_back(x);
	}
	int64 ans;
	if (n <= (int)vec.size()) {
		ans = std::accumulate(vec.begin(), vec.begin() + n, 0LL);
	} else {
		n -= (int)vec.size();
		ans = std::accumulate(vec.begin(), vec.end(), 0LL) + std::accumulate(cir.begin(), cir.end(), 0LL) * (n / (int)cir.size()) + std::accumulate(cir.begin(), cir.begin() + n % (int)cir.size(), 0LL);
	}
	printf("%lld\n", ans);
	return 0;
}

提出情報

提出日時
問題 E - Sequence Sum
ユーザ siyuan
言語 C++ (GCC 9.2.1)
得点 500
コード長 875 Byte
結果 AC
実行時間 8 ms
メモリ 4268 KiB

コンパイルエラー

./Main.cpp: In function ‘int main()’:
./Main.cpp:11:7: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   11 |  scanf("%lld%d%d", &n, &x, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 3
AC × 24
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
All hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, max_01.txt, max_02.txt, max_03.txt, max_11.txt, max_12.txt, max_13.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, sample_01.txt, sample_02.txt, sample_03.txt
ケース名 結果 実行時間 メモリ
hand_01.txt AC 6 ms 3632 KiB
hand_02.txt AC 2 ms 3608 KiB
hand_03.txt AC 3 ms 3988 KiB
hand_04.txt AC 2 ms 4144 KiB
hand_05.txt AC 5 ms 4268 KiB
max_01.txt AC 5 ms 4196 KiB
max_02.txt AC 6 ms 4220 KiB
max_03.txt AC 8 ms 4084 KiB
max_11.txt AC 2 ms 3960 KiB
max_12.txt AC 2 ms 4020 KiB
max_13.txt AC 3 ms 4028 KiB
random_01.txt AC 3 ms 3760 KiB
random_02.txt AC 2 ms 3828 KiB
random_03.txt AC 2 ms 3944 KiB
random_04.txt AC 2 ms 3608 KiB
random_05.txt AC 2 ms 3600 KiB
random_06.txt AC 2 ms 3740 KiB
random_07.txt AC 3 ms 3912 KiB
random_08.txt AC 2 ms 3976 KiB
random_09.txt AC 3 ms 3740 KiB
random_10.txt AC 2 ms 3892 KiB
sample_01.txt AC 2 ms 3648 KiB
sample_02.txt AC 2 ms 3604 KiB
sample_03.txt AC 2 ms 4152 KiB