結果

問題 No.136 Yet Another GCD Problem
ユーザー ふう
提出日時 2015-01-25 23:44:58
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,081 bytes
コンパイル時間 702 ms
コンパイル使用メモリ 81,384 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-23 03:00:46
合計ジャッジ時間 1,679 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14 WA * 25
権限があれば一括ダウンロードができます

ソースコード

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;

	 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 (cnt == k - 1) break;
                i--;
            }
        }
    }
	

	cout << tmp << endl;

	return (0);
}
0