結果

問題 No.889 素数!
ユーザー forest3
提出日時 2020-03-27 16:40:44
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 988 bytes
コンパイル時間 1,438 ms
コンパイル使用メモリ 165,528 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2025-01-02 08:40:36
合計ジャッジ時間 3,213 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 61
権限があれば一括ダウンロードができます

ソースコード

diff #

 #include <bits/stdc++.h>
using namespace std;

bool isPrime( long long x )
{
	if( x < 2 ) return false;
	if( x == 2 ) return true;
	if( x % 2 == 0 ) return false;
	for( long long i = 3; i * i <= x; i += 2 ) {
		if( x % i == 0 ) return false;
	}
	return true;
}

int main()
{
	int N;
	cin >> N;

	string ans;
	if( isPrime( N ) ) ans = "Sosu!";
	if( ans.empty() ) {
		for( int i = 2; i * i <= N; i++ ) {
			if( i * i == N ) {
				ans = "Heihosu!";
				break;
			}
		}
	}
	if( ans.empty() ) {
		for( int i = 2; i * i * i <= N; i++ ) {
			if( i * i * i == N ) {
				ans = "Ripposu!";
				break;
			}
		}
	}
	if( ans.empty() ) {
		vector<int> v;
		for( int i = 1; i * i <= N; i++ ) {
			if( N % i == 0 ) {
				v.push_back( i );
				if( i != 1 && N / i != i ) v.push_back( N / i );
			}
		}
		int sum = 0;
		for( int i = 0; i < v.size(); i++ ) {
			sum += v[i];
		}
		if( sum == N && N != 0 && N != 1 ) ans = "Kanzensu!";
	}

	if( ans.empty() ) cout << N << endl;
	else cout << ans << endl;
}
0