Submission #968304
Source Code Expand
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
class Program
{
public Program() { }
static void Main(string[] args)
{
new Program().prog();
}
Scanner cin;
const int MOD = 1000000007;
const int INF = int.MaxValue;
const long INFL = long.MaxValue;
const double EPS = 1e-7;
const double PI = 3.1415926536;
int[] p = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101 };
int MAX = 1000000000;
void prog()
{
cin = new Scanner();
int[,] dir8 = new int[8, 2] { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 } };
int[,] dir4 = new int[4, 2] { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };
int N = cin.nextInt();
int K = cin.nextInt();
int[] A = new int[N];
Dictionary<int, int> dict = new Dictionary<int, int>();
long ans = 0;
for (int i = 0; i < N; i++)
{
A[i] = Gcd(cin.nextInt(), K);
}
for (int i = 0; i < N; i++)
{
if (dict.ContainsKey(A[i]))
{
dict[A[i]]++;
}
else
{
dict.Add(A[i], 1);
}
}
IOrderedEnumerable<Pair> en = dict.OrderBy(_ => _.Key);
foreach(var a in en)
{
foreach (var b in en)
{
if (b.Key < a.Key) continue;
else if ((long)a.Key * b.Key % K == 0)
{
if (a.Key == b.Key)
{
ans += (long)a.Value * (a.Value - 1) / 2;
}
else
{
ans += (long)a.Value * b.Value;
}
}
}
}
Console.WriteLine(ans);
}
// 最大公約数
int Gcd(int a, int b)
{
if (b == 0) return a;
else return Gcd(b, a % b);
}
}
class Scanner
{
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner()
{
s = new string[0];
i = 0;
}
public string next()
{
if (i < s.Length) return s[i++];
string st = Console.ReadLine();
while (st == "") st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return next();
}
public int nextInt()
{
return int.Parse(next());
}
public long nextLong()
{
return long.Parse(next());
}
public double nextDouble()
{
return double.Parse(next());
}
}
Submission Info
Submission Time |
|
Task |
C - ロト2 |
User |
furuya1223 |
Language |
C# (Mono 4.6.2.0) |
Score |
400 |
Code Size |
2351 Byte |
Status |
AC |
Exec Time |
600 ms |
Memory |
33516 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
400 / 400 |
Status |
|
|
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 |
30 ms |
3416 KB |
00_example_02.txt |
AC |
26 ms |
3032 KB |
00_example_03.txt |
AC |
27 ms |
3032 KB |
10_random_01.txt |
AC |
27 ms |
3032 KB |
10_random_02.txt |
AC |
27 ms |
3160 KB |
10_random_03.txt |
AC |
27 ms |
3032 KB |
10_random_04.txt |
AC |
28 ms |
3032 KB |
10_random_05.txt |
AC |
27 ms |
3032 KB |
20_max_01.txt |
AC |
136 ms |
19672 KB |
20_max_02.txt |
AC |
133 ms |
19672 KB |
20_max_03.txt |
AC |
148 ms |
20696 KB |
20_max_04.txt |
AC |
132 ms |
19544 KB |
20_max_05.txt |
AC |
144 ms |
18560 KB |
30_overflow_01.txt |
AC |
128 ms |
19024 KB |
30_overflow_02.txt |
AC |
129 ms |
19024 KB |
40_dmax_01.txt |
AC |
600 ms |
33516 KB |
40_dmax_02.txt |
AC |
598 ms |
33516 KB |
40_dmax_03.txt |
AC |
599 ms |
33512 KB |
50_prime_01.txt |
AC |
136 ms |
19796 KB |
50_prime_02.txt |
AC |
142 ms |
20312 KB |
50_prime_03.txt |
AC |
148 ms |
20944 KB |
60_prime_pow_01.txt |
AC |
146 ms |
20944 KB |
60_prime_pow_02.txt |
AC |
147 ms |
20688 KB |
60_prime_pow_03.txt |
AC |
145 ms |
20824 KB |
70_one_01.txt |
AC |
124 ms |
19160 KB |