結果

問題 No.1396 Giri
ユーザー
提出日時 2021-02-14 21:35:19
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 820 bytes
コンパイル時間 724 ms
コンパイル使用メモリ 92,972 KB
実行使用メモリ 11,316 KB
最終ジャッジ日時 2024-07-22 08:58:09
合計ジャッジ時間 1,940 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:39:17: warning: 'no' may be used uninitialized [-Wmaybe-uninitialized]
   39 |                 if (i != no) {
      |                 ^~
main.cpp:19:22: note: 'no' was declared here
   19 |         long long n, no;
      |                      ^~

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long x[1000010];
int main() {
	long long n, no;
	long long mod = 998244353;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		x[i] = 1;
	}
	for (int i = n; i > 0; i--) {
		bool bo = true;
		for (int j = 2; j * j <= n; j++) {
			if (i % j == 0) {
				bo = false;
			}
		}
		if (bo) {
			no = i;
			break;
		}
	}
	long long ans = 1;
	for (int i = 2; i <= n; i++) {
		if (i != no) {
			long long now = i / x[i];
			ans *= now;
			for (int j = i + i; j <= n; j += i) {
				x[j] *= now;
			}
			ans %= mod;
		}
	}
	cout << ans << endl;
}
0