結果

問題 No.136 Yet Another GCD Problem
ユーザー ふうふう
提出日時 2015-01-25 23:57:02
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,175 bytes
コンパイル時間 1,161 ms
コンパイル使用メモリ 80,916 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-05 06:44:57
合計ジャッジ時間 2,491 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 2 ms
4,380 KB
testcase_24 WA -
testcase_25 AC 1 ms
4,376 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 WA -
testcase_34 AC 3 ms
4,380 KB
testcase_35 AC 4 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 6 ms
4,376 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 1 ms
4,380 KB
testcase_41 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <map>
#include <list>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <iomanip>

using namespace std;

int gcd(int a, int b)
{
	int tmp, r;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}
	while (1) {
		r = a % b;
		if (r == 0) break;
		a = b;
		b = r;
	}

	return (b);
}

bool is_prime(int n)
{
    if (n == 2) return (true);
    if (n <= 1 || n % 2 == 0) return (false);
    for (int i = 3; i * i <= n; i += 2) {
        if (n % i == 0) return (false);
    }

    return (true);
}

int main(void)
{
	int n, k;
	int cnt = 0;
	int tmp;

	cin >> n >> k;
	
	tmp = n;

	if (n % k == 0) {
		cout << n / k << endl;
	} 

	 for (int i = 2; i <= n; i++) {
        if (tmp == 1) break;
        if (is_prime(i)) {
            if (tmp % i == 0) {
				cnt++;
				
                //cout << " " << i;
                tmp /= i;
				if (tmp == 1 && cnt == k - 1) tmp = i;  
				if (cnt == k - 1) break;
                i--;
            }
        }
    }
	

	cout << tmp << endl;

	return (0);
}
0