結果

問題 No.473 和と積の和
ユーザー FF256grhyFF256grhy
提出日時 2016-12-23 11:21:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 965 ms / 3,000 ms
コード長 3,115 bytes
コンパイル時間 1,977 ms
コンパイル使用メモリ 164,652 KB
実行使用メモリ 42,120 KB
最終ジャッジ日時 2023-08-22 09:03:40
合計ジャッジ時間 9,301 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 551 ms
25,864 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 5 ms
4,960 KB
testcase_24 AC 4 ms
4,908 KB
testcase_25 AC 965 ms
42,120 KB
testcase_26 AC 361 ms
22,104 KB
testcase_27 AC 327 ms
24,460 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 3 ms
4,380 KB
testcase_31 AC 3 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 286 ms
24,524 KB
testcase_35 AC 624 ms
31,760 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 790 ms
33,556 KB
testcase_39 AC 446 ms
23,276 KB
testcase_40 AC 386 ms
23,164 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 20 ms
8,600 KB
testcase_43 AC 303 ms
18,056 KB
testcase_44 AC 715 ms
26,824 KB
testcase_45 AC 2 ms
4,384 KB
testcase_46 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define inc( i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec( i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(i, v) for(auto i =  v.begin(); i !=  v.end(); ++i)
#define RFOR(i, v) for(auto i = v.rbegin(); i != v.rend(); ++i)

template<typename T> bool setmin(T & a, T b) { if(a <= b) { return false; } else { a = b; return true; } }
template<typename T> bool setmax(T & a, T b) { if(b <= a) { return false; } else { a = b; return true; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T> ostream & operator<<(ostream & os, const vector<T> & v) {
	os << "[";
	FOR(it, v) {
		if(it != v.begin()) { os << ", "; }
		os << *it;
	}
	os << "]";
	return os;
}
template<typename F, typename S> ostream & operator<<(ostream & os, const pair<F, S> & p) {
	os << "<" << p.FI << ", " << p.SE << ">";
	return os;
}

// ---- ----

int n, x;
vector<pair<int, int>> pe;
int pn, et;

vector<pair<LL, int>> ivs;
map<LL, int> vi;
pair<bool, int> memo[30][1400][1400];
int ans;

void search(int i, int total, int pre) {
	if(memo[i][total][pre].FI) { ans += memo[i][total][pre].SE; return; }
	LL ans_n = ans;
	
	if(i == n) {
		if(ivs[total].FI == x) { ans++; }
		return;
	}
	
	incID(j, pre, ivs.size()) {
		LL m = ivs[total].FI * ivs[j].FI;
		if(ivs[total].SE + ivs[j].SE + (n - i - 1) <= et && x % m == 0) {
			search(i + 1,  vi[m], j);
		}
	}
	
	memo[i][total][pre].FI = true;
	memo[i][total][pre].SE = ans - ans_n;
}

int main() {
	cin >> n >> x;
	x++;
	
	if(n >= 30) { cout << 0 << endl; return 0; }
	
	int xx = x;
	for(int i = 2; i * i <= xx; i++) {
		if(xx % i == 0) {
			int j = 0;
			while(xx % i == 0) {
				xx /= i;
				j++;
			}
			pe.EB(i, j);
		}
	}
	if(xx != 1) { pe.EB(xx, 1); }
	pn = pe.size();
	inc(i, pn) { et += pe[i].SE; }
	
	// cout << pe << endl;
	
	
	if(et == 1) { cout << 0 << endl; return 0; }
	
	vector<int> d;
	inc(i, pn) { d.PB(0); }
	LL v = 1, s = 0;
	int c = 0;
	while(true) {
		// cout << d << endl;
		ivs.EB(v, s);
		
		c = 0;
		while(c < pn && d[c] == pe[c].SE) { inc(i, pe[c].SE) { v /= pe[c].FI; } s -= pe[c].SE; d[c++] = 0; }
		if(c == pn) { break; }
		v *= pe[c].FI;
		s++;
		d[c]++;
	}
	
	sort(ALL(ivs));
	inc(i, ivs.size()) {
		vi[ ivs[i].FI ] = i;
	}
	
	// cout << ivs << endl;
	
	search(0, 0, 1);
	
	cout << ans << endl;
	
	return 0;
}
0