結果

問題 No.7 プライムナンバーゲーム
ユーザー sasa
提出日時 2025-03-10 16:07:02
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 489 bytes
コンパイル時間 508 ms
コンパイル使用メモリ 27,776 KB
実行使用メモリ 8,860 KB
最終ジャッジ日時 2025-03-10 16:07:16
合計ジャッジ時間 13,343 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other TLE * 1 -- * 16
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:6:21: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
    6 |         char *ans = "Win";
      |                     ^~~~~
main.cpp:22:47: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
   22 |                                         ans = "Lose";
      |                                               ^~~~~~
main.cpp:24:47: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
   24 |                                         ans = "Win";
      |                                               ^~~~~
main.cpp:4:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    4 |         scanf("%d",&num);
      |         ~~~~~^~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
int main(void){
	int num = 0;
	scanf("%d",&num);
	
	char *ans = "Win";
	
	int isPrime = 0;
	while(num != 1 && num != 0){
		for(int i = num - 1; num >= 0;i--){
			for (int j = 2; j < i; j++) {
				if (i % j == 0) {
					isPrime++; // 割り切れる場合は素数ではない
					break;
				}
			}
			if(isPrime != 0){
				isPrime = 0;	
			}else{
				num -= i;
				if(ans == "Win"){
					ans = "Lose";
				}else{
					ans = "Win";
				}
			}
		}
	}
	printf("%s",ans);
}
0