結果

問題 No.414 衝動
ユーザー hiyokko2hiyokko2
提出日時 2016-08-26 22:48:32
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 463 bytes
コンパイル時間 1,768 ms
コンパイル使用メモリ 159,588 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-26 02:20:00
合計ジャッジ時間 3,409 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 3 ms
6,944 KB
testcase_03 AC 8 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 8 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 5 ms
6,944 KB
testcase_12 AC 3 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:13:52: warning: iteration 999999 invokes undefined behavior [-Waggressive-loop-optimizations]
   13 |         for (int i=2; i<=1000001; i++) is_prime[i] = true;
      |                                        ~~~~~~~~~~~~^~~~~~
main.cpp:13:24: note: within this loop
   13 |         for (int i=2; i<=1000001; i++) is_prime[i] = true;
      |                       ~^~~~~~~~~
main.cpp:13:52: warning: ‘void* __builtin_memset(void*, int, long unsigned int)’ writing 1000000 bytes into a region of size 999999 overflows the destination [-Wstringop-overflow=]
   13 |         for (int i=2; i<=1000001; i++) is_prime[i] = true;
      |                                        ~~~~~~~~~~~~^~~~~~
main.cpp:6:6: note: at offset 2 into destination object ‘is_prime’ of size 1000001
    6 | bool is_prime[1000001];
      |      ^~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;

bool is_prime[1000001];
int M;

signed main()
{
	cin >> M;

	for (int i=2; i<=1000001; i++) is_prime[i] = true;
	for (int i=2; i<=1000001; i++) {
		if (is_prime[i]) {
			if (M % i == 0) {
				cout << i << " " << M / i << endl;
				return 0;
			}
			for (int j=i*2; j<=1000001; j+=i) {
				is_prime[j] = false;
			}
		}
	}

	cout << 1 << " " << M << endl;
}
0