結果
問題 | No.811 約数の個数の最大化 |
ユーザー | chocopuu |
提出日時 | 2019-04-13 01:10:56 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 85 ms / 2,000 ms |
コード長 | 1,765 bytes |
コンパイル時間 | 1,485 ms |
コンパイル使用メモリ | 169,748 KB |
実行使用メモリ | 4,352 KB |
最終ジャッジ日時 | 2023-10-13 09:25:17 |
合計ジャッジ時間 | 2,771 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | AC | 2 ms
4,352 KB |
testcase_02 | AC | 73 ms
4,348 KB |
testcase_03 | AC | 2 ms
4,352 KB |
testcase_04 | AC | 2 ms
4,352 KB |
testcase_05 | AC | 3 ms
4,352 KB |
testcase_06 | AC | 6 ms
4,348 KB |
testcase_07 | AC | 7 ms
4,348 KB |
testcase_08 | AC | 34 ms
4,348 KB |
testcase_09 | AC | 35 ms
4,348 KB |
testcase_10 | AC | 22 ms
4,348 KB |
testcase_11 | AC | 71 ms
4,352 KB |
testcase_12 | AC | 17 ms
4,348 KB |
testcase_13 | AC | 84 ms
4,352 KB |
testcase_14 | AC | 85 ms
4,348 KB |
コンパイルメッセージ
次のファイルから読み込み: /usr/local/gcc7/include/c++/12.2.0/istream:39, 次から読み込み: /usr/local/gcc7/include/c++/12.2.0/sstream:38, 次から読み込み: /usr/local/gcc7/include/c++/12.2.0/complex:45, 次から読み込み: /usr/local/gcc7/include/c++/12.2.0/ccomplex:39, 次から読み込み: /usr/local/gcc7/include/c++/12.2.0/x86_64-pc-linux-gnu/bits/stdc++.h:54, 次から読み込み: main.cpp:1: メンバ関数 ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>]’ 内, inlined from ‘int main()’ at main.cpp:58:11: /usr/local/gcc7/include/c++/12.2.0/ostream:202:25: 警告: ‘id’ may be used uninitialized [-Wmaybe-uninitialized] 202 | { return _M_insert(__n); } | ~~~~~~~~~^~~~~ main.cpp: 関数 ‘int main()’ 内: main.cpp:43:15: 備考: ‘id’ はここで定義されています 43 | int ans=0,id; | ^~
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define fi first #define se second #define rep(i,s,n) for(int i = s;i<n;i++) #define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--) #define all(v) (v).begin(),(v).end() #define chmin(a,b) a=min((a),(b)) #define chmax(a,b) a=max((a),(b)) #define endl '\n' #define IOS() ios_base::sync_with_stdio(0);cin.tie(0) typedef long long ll; typedef pair<int,int>pint; typedef vector<int>vint; typedef vector<pint>vpint; const ll MOD=1000000007,INF=1e18; int dx[]={0,0,1,-1},dy[]={-1,1,0,0}; typedef pair<int,pint>P2; int N,K; vector<pair<long long, long long> > prime_factorize(long long n) { vector<pair<long long, long long> > res; for (long long p = 2; p * p <= n; ++p) { if (n % p != 0) continue; int num = 0; while (n % p == 0) { ++num; n /= p; } res.push_back(make_pair(p, num)); } if (n != 1) res.push_back(make_pair(n, 1)); return res; } signed main() { IOS(); cin>>N>>K; auto v=prime_factorize(N); vint cnt(100010,0); for(auto e:v)cnt[e.fi]=e.se; int ans=0,id; rep(i,1,N){ auto tmp=prime_factorize(i); int t=0,sum=1; for(auto e:tmp){ sum*=e.se+1; t+=min(e.se,cnt[e.fi]); } if(t>=K){ if(ans<sum){ ans=sum; id=i; } } } cout<<id<<endl; return 0; }