結果
問題 | No.811 約数の個数の最大化 |
ユーザー |
![]() |
提出日時 | 2019-04-19 11:40:10 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 104 ms / 2,000 ms |
コード長 | 1,585 bytes |
コンパイル時間 | 1,726 ms |
コンパイル使用メモリ | 174,080 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-22 11:22:08 |
合計ジャッジ時間 | 2,611 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/istream:39, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/sstream:38, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/complex:45, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ccomplex:39, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:54, from main.cpp:1: In member function '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:84:5: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ostream:202:25: warning: 'max_M' may be used uninitialized [-Wmaybe-uninitialized] 202 | { return _M_insert(__n); } | ~~~~~~~~~^~~~~ main.cpp: In function 'int main()': main.cpp:73:8: note: 'max_M' was declared here 73 | ll max_M; | ^~~~~
ソースコード
#include<bits/stdc++.h>using namespace std;using ll = long long;#define FOR(i,a,b) for(ll i=(a);i<(b);++i)#define ALL(v) (v).begin(), (v).end()#define p(s) cout<<(s)<<endl#define p2(s, t) cout << (s) << " " << (t) << endl#define br() p("")#define pn(s) cout << (#s) << " " << (s) << endl#define p_yes() p("Yes")#define p_no() p("No")const ll mod = 1e9 + 7;const ll inf = 1e18;ll gcd(ll a,ll b){if(b == 0) return a;return gcd(b,a%b);}map<ll, ll> factorize(ll n){map<ll, ll> mp;ll sq = sqrt(n);FOR(i, 2, sq+1){while(n%i==0){mp[i]++;n/=i;}}// 残りif(n!=1){mp[n]++;}return mp;}// 素因数の個数 (重複あり) ex. {2, 2, 2, 3}ll prime_factor_num(ll a){ll count = 0;auto mp = factorize(a);for(auto p : mp){count += p.second;}return count;}// a, bの共通の素因数の数ll common(ll a, ll b){ll g = gcd(a, b);return prime_factor_num(g);}// 約数の個数ll divisor_num(ll a){auto mp = factorize(a);ll ret = 1;for(auto p : mp){ret *= (p.second + 1);}return ret;}int main(){cin.tie(0);ios::sync_with_stdio(false);// inputll N, K;cin >> N >> K;ll max_divisor_num = 0;ll max_M;FOR(i, 1, N){if(common(i, N)>=K){ll div = divisor_num(i);if(div > max_divisor_num){max_divisor_num = div;max_M = i;}}}p(max_M);return 0;}