Submission #6945065


Source Code Expand

Copy
//disco2016_c.cpp
//Sat Aug 17 09:59:30 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

ll gcd (ll a, ll b){ //最大公約数
	if (b == 0){
		return a;
	}
	return gcd(b, a%b);
}

ll lcm (ll a, ll b){ //最小公倍数
	ll temp = gcd(a,b);
	return (a/temp)*b;
}

int main(){
	ll n,k;
	cin >> n >> k;

	ll a[n];
	unordered_map<ll,ll> mp;
	for (int i=0;i<n;i++){
		cin >> a[i];
		ll temp = gcd(a[i],k);
		mp[temp]++;
	}

	ll ans = 0;
	for (auto itr=mp.begin();itr!=mp.end();itr++){
		for (auto itr2=itr;itr2!=mp.end();itr2++){
			if (itr==itr2){
				if ((itr->first)%k==0){
					ans += (itr->second)*(itr->second-1)/2;
				}
			}else if (((itr->first)*(itr2->first))%k==0){
				ans += (itr->second) * (itr2->second);
			}
		}
	}

	cout << ans << endl;
}

Submission Info

Submission Time
Task C - ロト2
User hornistyf
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1059 Byte
Status
Exec Time 107 ms
Memory 1920 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 00_example_01.txt, 00_example_02.txt, 00_example_03.txt
All 0 / 400 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 1 ms 256 KB
00_example_02.txt 1 ms 256 KB
00_example_03.txt 1 ms 256 KB
10_random_01.txt 1 ms 256 KB
10_random_02.txt 1 ms 256 KB
10_random_03.txt 1 ms 256 KB
10_random_04.txt 1 ms 256 KB
10_random_05.txt 1 ms 256 KB
20_max_01.txt 75 ms 1792 KB
20_max_02.txt 73 ms 1792 KB
20_max_03.txt 92 ms 1792 KB
20_max_04.txt 72 ms 1792 KB
20_max_05.txt 107 ms 1792 KB
30_overflow_01.txt 68 ms 1792 KB
30_overflow_02.txt 68 ms 1792 KB
40_dmax_01.txt 101 ms 1920 KB
40_dmax_02.txt 101 ms 1920 KB
40_dmax_03.txt 102 ms 1920 KB
50_prime_01.txt 75 ms 1792 KB
50_prime_02.txt 85 ms 1792 KB
50_prime_03.txt 93 ms 1792 KB
60_prime_pow_01.txt 91 ms 1792 KB
60_prime_pow_02.txt 90 ms 1792 KB
60_prime_pow_03.txt 94 ms 1792 KB
70_one_01.txt 61 ms 1792 KB