結果
問題 | No.136 Yet Another GCD Problem |
ユーザー |
![]() |
提出日時 | 2015-01-25 23:56:42 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 666 bytes |
コンパイル時間 | 1,377 ms |
コンパイル使用メモリ | 164,864 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-23 03:02:03 |
合計ジャッジ時間 | 2,427 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 39 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define REP(i,a,b) for(int i=a;i<(int)b;i++) #define rep(i,n) REP(i,0,n) map<int,int> pfact(int n) { map<int, int> ret; for(int i=2; i*i<=n; i++) { while(n%i == 0) { ++ret[i]; n/=i; } } if(n!=1) ret[n] = 1; return ret; } int main() { int N, K; cin >> N >> K; K = min(N, K)-1; map<int, int> mp = pfact(N); long long ans = 1; bool thru = 0; for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++) { while(it->second > 0) { if(!thru) { it->second--; thru = 1; } else { ans *= it->first; it->second --; } } } cout << ans << endl; return 0; }