Submission #968116


Source Code Expand

#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8

vector<int> div, cntk;
int encode(const vector<int> &cnt){
	int e = 0;
	for(size_t i = 0; i < cnt.size(); ++i){
		e = e * (cntk[i] + 1) + cnt[i];
	}
	return e;
}

LL solve(){
	LL n, k0;
	cin >> n >> k0;

	LL k = k0;
	for(LL i = 2; i * i <= k; ++i){
		int c;
		for(c = 0; k % i == 0; ++c){ k /= i; }
		if(c){
			div.push_back(i);
			cntk.push_back(c);
		}
	}
	if(k > 1){
		div.push_back(k);
		cntk.push_back(1);
	}
	int sz = div.size();
	LL ans = 0;
	int maxe = encode(cntk);
	vector<LL> cs(maxe + 1);
	for(int i = 0; i < n; ++i){
		LL a;
		cin >> a;
		vector<int> v(sz);
		for(int j = 0; j < sz; ++j){
			int c;
			for(c = 0; a % div[j] == 0; ++c){ a /= div[j]; }
			v[j] = min(c, cntk[j]);
		}
		int e = encode(v);
		++cs[e];
	}
	VV(int) encs(maxe + 1);
	vector<int> tmp = cntk;
	while(1){
		int e1 = encode(tmp);
		encs[e1] = tmp;

		int j;
		for(j = 0; j < sz && !tmp[j]; ++j){
			tmp[j] = cntk[j];
		}
		if(j == sz){ break; }
		--tmp[j];
	}

	for(int e1 = 0; e1 <= maxe; ++e1)
	for(int e2 = e1; e2 <= maxe; ++e2){
		bool ok = true;
		for(int i = 0; i < sz; ++i){
			if(encs[e1][i] + encs[e2][i] < cntk[i]){
				ok = false;
				break;
			}
		}
		if(ok){
			if(e1 == e2){
				ans += cs[e1] * (cs[e1] - 1) / 2;
			}
			else{
				ans += cs[e1] * cs[e2];
			}
		}
	}

	return ans;
}

void mainmain(){
	cout << solve() << endl;
}



}
int main() try{
//	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}

Submission Info

Submission Time
Task C - ロト2
User climpet
Language C++14 (GCC 5.4.1)
Score 400
Code Size 3076 Byte
Status AC
Exec Time 192 ms
Memory 384 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 25
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt, 00_example_03.txt
All 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 10_random_01.txt, 10_random_02.txt, 10_random_03.txt, 10_random_04.txt, 10_random_05.txt, 20_max_01.txt, 20_max_02.txt, 20_max_03.txt, 20_max_04.txt, 20_max_05.txt, 30_overflow_01.txt, 30_overflow_02.txt, 40_dmax_01.txt, 40_dmax_02.txt, 40_dmax_03.txt, 50_prime_01.txt, 50_prime_02.txt, 50_prime_03.txt, 60_prime_pow_01.txt, 60_prime_pow_02.txt, 60_prime_pow_03.txt, 70_one_01.txt
Case Name Status Exec Time Memory
00_example_01.txt AC 3 ms 256 KB
00_example_02.txt AC 3 ms 256 KB
00_example_03.txt AC 3 ms 256 KB
10_random_01.txt AC 3 ms 256 KB
10_random_02.txt AC 3 ms 256 KB
10_random_03.txt AC 3 ms 256 KB
10_random_04.txt AC 3 ms 256 KB
10_random_05.txt AC 3 ms 256 KB
20_max_01.txt AC 124 ms 256 KB
20_max_02.txt AC 105 ms 256 KB
20_max_03.txt AC 126 ms 256 KB
20_max_04.txt AC 112 ms 256 KB
20_max_05.txt AC 143 ms 256 KB
30_overflow_01.txt AC 103 ms 256 KB
30_overflow_02.txt AC 107 ms 256 KB
40_dmax_01.txt AC 191 ms 384 KB
40_dmax_02.txt AC 192 ms 384 KB
40_dmax_03.txt AC 192 ms 384 KB
50_prime_01.txt AC 106 ms 256 KB
50_prime_02.txt AC 115 ms 256 KB
50_prime_03.txt AC 135 ms 256 KB
60_prime_pow_01.txt AC 182 ms 256 KB
60_prime_pow_02.txt AC 131 ms 256 KB
60_prime_pow_03.txt AC 127 ms 256 KB
70_one_01.txt AC 82 ms 256 KB