Submission #967754


Source Code Expand

#include <map>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;

// ------------ Greatest Common Divisor (Update 8/7) ------------ //
inline unsigned long long gcd(unsigned long long x, unsigned long long y) {
	while (y != 0) {
		unsigned long long r = x;
		x = y;
		y = r % y;
	}
	return x;
}

// ------------ Prime Factorization (Update 8/6) ------------ //
std::map<unsigned long long, unsigned> prime_factorize(unsigned long long x) {
	std::map<unsigned long long, unsigned> ret;
	for (unsigned i = 2; 1ULL * i * i <= x; i++) {
		while (x % i == 0) x /= i, ret[i]++;
	}
	if (x != 1) ret[x]++;
	return ret;
}

// ------------ Enumerate Divisors (Update 10/27) ------------ //
std::vector<unsigned long long> calc_divisors(unsigned long long x) {
	std::map<unsigned long long, unsigned> res = prime_factorize(x);
	std::vector<unsigned long long> ret; ret.push_back(1);
	for (std::pair<unsigned long long, unsigned> w : res) {
		int s = ret.size();
		unsigned long long mul = 1;
		for (int i = 0; i < w.second; i++) {
			mul *= w.first;
			for (int j = 0; j < s; j++) ret.push_back(ret[j] * mul);
		}
	}
	sort(ret.begin(), ret.end());
	return ret;
}

int n, m, a[200009];
int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) cin >> a[i];
	vector<unsigned long long> v = calc_divisors(m);
	vector<int> c(v.size());
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < c.size(); j++) {
			if (a[i] % v[j] == 0) c[j]++;
		}
	}
	long long ret = 0;
	for (int i = 0; i < n; i++) {
		int e = m / gcd(a[i], m);
		int ptr = lower_bound(v.begin(), v.end(), e) - v.begin();
		ret += c[ptr];
	}
	for (int i = 0; i < n; i++) {
		if (1LL * a[i] * a[i] % m == 0) ret--;
	}
	cout << ret / 2 << endl;
	return 0;
}

Submission Info

Submission Time
Task C - ロト2
User square1001
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1859 Byte
Status TLE
Exec Time 2102 ms
Memory 1024 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 3
AC × 22
TLE × 3
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 384 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 96 ms 1024 KB
20_max_02.txt AC 80 ms 1024 KB
20_max_03.txt AC 111 ms 1024 KB
20_max_04.txt AC 84 ms 1024 KB
20_max_05.txt AC 142 ms 1024 KB
30_overflow_01.txt AC 101 ms 1024 KB
30_overflow_02.txt AC 101 ms 1024 KB
40_dmax_01.txt TLE 2102 ms 1024 KB
40_dmax_02.txt TLE 2102 ms 1024 KB
40_dmax_03.txt TLE 2102 ms 1024 KB
50_prime_01.txt AC 81 ms 1024 KB
50_prime_02.txt AC 90 ms 1024 KB
50_prime_03.txt AC 112 ms 1024 KB
60_prime_pow_01.txt AC 157 ms 1024 KB
60_prime_pow_02.txt AC 105 ms 1024 KB
60_prime_pow_03.txt AC 101 ms 1024 KB
70_one_01.txt AC 66 ms 1024 KB