結果
問題 | No.811 約数の個数の最大化 |
ユーザー | to10to10to10to |
提出日時 | 2019-04-13 18:58:49 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 51 ms / 2,000 ms |
コード長 | 1,124 bytes |
コンパイル時間 | 1,535 ms |
コンパイル使用メモリ | 167,244 KB |
実行使用メモリ | 4,352 KB |
最終ジャッジ日時 | 2023-10-13 14:31:46 |
合計ジャッジ時間 | 2,687 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,352 KB |
testcase_01 | AC | 2 ms
4,352 KB |
testcase_02 | AC | 27 ms
4,348 KB |
testcase_03 | AC | 1 ms
4,348 KB |
testcase_04 | AC | 2 ms
4,352 KB |
testcase_05 | AC | 2 ms
4,352 KB |
testcase_06 | AC | 3 ms
4,348 KB |
testcase_07 | AC | 3 ms
4,348 KB |
testcase_08 | AC | 12 ms
4,348 KB |
testcase_09 | AC | 14 ms
4,348 KB |
testcase_10 | AC | 7 ms
4,352 KB |
testcase_11 | AC | 14 ms
4,348 KB |
testcase_12 | AC | 5 ms
4,348 KB |
testcase_13 | AC | 51 ms
4,348 KB |
testcase_14 | AC | 20 ms
4,352 KB |
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内: main.cpp:67:11: 警告: ‘ans’ may be used uninitialized [-Wmaybe-uninitialized] 67 | cout << ans << endl; | ^~~ main.cpp:53:16: 備考: ‘ans’ はここで定義されています 53 | int n,k,ma=0,ans; | ^~~
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define reps(i,a,b) for(int i=(a);i<(b);++i) #define rep(i,n) reps(i,0,n) #define all(x) (x).begin(),(x).end() #define INF (1000000000) #define MOD (1000000007) #define PI (acos(-1)) vector<int> divisor(int n){ vector<int> div; for(int i=1; i*i<=n; i++){ if(n%i==0){ div.push_back(i); if(i*i!=n){ div.push_back(n/i); } } } return div; } int prime_factorize(int n){//nの素因数の数 int tmp = n,cnt=0; if(n==1)return 0; for(int p=2; p<=tmp; p++){ if(n%p!=0)continue; while(n%p==0){ cnt++; n/=p; } } if(n!=1)return 1; return cnt; } int gcd(int a,int b){ if(a<b){ swap(a,b); } int r; while(b>0){ r = a%b; a = b; b = r; } return a; } int main(){ int n,k,ma=0,ans; cin >> n >> k; reps(i,1,n){ int g = gcd(i,n); int p = prime_factorize(g); //cout << i << " " << g << " " << p << endl; if(p >= k){ int d = divisor(i).size(); if(d > ma){ ma = d; ans = i; } } } cout << ans << endl; }