結果
問題 |
No.473 和と積の和
|
ユーザー |
![]() |
提出日時 | 2021-05-13 00:29:31 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,100 bytes |
コンパイル時間 | 1,564 ms |
コンパイル使用メモリ | 128,176 KB |
最終ジャッジ日時 | 2025-01-21 10:23:29 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 37 TLE * 6 |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <set> #include <map> #include <tuple> #include <cmath> #include <numeric> #include <functional> #include <cassert> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; vector<ll> enumarate_facs(ll n){ vector<ll> ans; for(int i = 1; i*i <= n; i++){ if(n%i == 0){ ans.push_back(i); if(i*i != n) ans.push_back(n/i); } } sort(ans.begin(), ans.end()); return ans; } ll n, x; int ans; void dfs(int i, int j, int k, vector<ll> &facs, vector<vector<int>> &inv){ int m = facs.size(); // cout << "dfs(" << i << "," << facs[j] << "," << facs[k] << ")" << endl; if(i == n){ if(k == m-1) ans++; return; } for(int l = max(j, 1); l < m; l++){ if(inv[k][l] == -1) continue; dfs(i+1, l, inv[k][l], facs, inv); } } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; cin >> n >> x; if(n > 30){ cout << 0 << endl; return 0; } x++; auto facs = enumarate_facs(x); int m = facs.size(); vector<vector<int>> inv(m, vector<int>(m, -1)); map<ll, int> mp = [&](){ map<ll, int> ans; for(int i = 0; i < m; i++) ans[facs[i]] = i; return ans; }(); for(int i = 0; i < m; i++){ for(int j = 0; j < m; j++){ ll p = facs[i]*facs[j]; if(p > x) continue; if(x%p == 0){ // cout << facs[i] << '*' << facs[j] << '=' << facs[mp[p]] << endl; inv[i][j] = mp[p]; } } } dfs(0, 0, 0, facs, inv); cout << ans << endl; }