結果
問題 |
No.473 和と積の和
|
ユーザー |
![]() |
提出日時 | 2018-09-22 12:44:25 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 897 bytes |
コンパイル時間 | 726 ms |
コンパイル使用メモリ | 83,440 KB |
実行使用メモリ | 13,752 KB |
最終ジャッジ日時 | 2024-07-18 08:55:03 |
合計ジャッジ時間 | 6,459 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 TLE * 1 -- * 21 |
ソースコード
#include <cstdio> #include <cstring> #include <iostream> #include <string> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> using namespace std; typedef long long int ll; typedef pair<int, int> P; int n; vector<ll> dv; int ans; ll x; vector<ll> p; ll pr; void solve(int i){ if(i==n-1){ if(x%pr==0 && p.back()<=x/pr) ans++; return; } int j=1; if(i>0){ j=lower_bound(dv.begin(), dv.end(), p.back())-dv.begin(); } for(; j<dv.size(); j++){ if(pr*dv[j]>x) break; if((x/pr)%dv[j]!=0) continue; p.push_back(dv[j]); pr*=dv[j]; solve(i+1); pr/=dv[j]; p.pop_back(); } } int main() { cin>>n>>x; x++; pr=1; for(ll i=1; i*i<=x; i++){ if(x%i!=0) continue; dv.push_back(i); if(i*i<x) dv.push_back(x/i); } sort(dv.begin(), dv.end()); pr=1; solve(0); cout<<ans<<endl; return 0; }