Pagini recente » Cod sursa (job #52945) | Cod sursa (job #1630047) | Cod sursa (job #1469927) | Cod sursa (job #731848) | Cod sursa (job #2883100)
#include <bits/stdc++.h>
#define NUMMAX 1000005
using namespace std;
/*******************************/
// INPUT / OUTPUT
ifstream f("pairs.in");
ofstream g("pairs.out");
/*******************************/
/// GLOBAL DECLARATIONS
int N;
long long ans;
int x, maxNum;
bool ciur[NUMMAX], sqrd[NUMMAX], freq[NUMMAX];
int nr[NUMMAX];
/*******************************/
/// FUNCTIONS
void ReadInput();
void Solution();
void Output();
/*******************************/
///-------------------------------------
inline void ReadInput()
{
f >> N;
for (int i = 1 ; i <= N ; ++ i)
{
f >> x;
freq[x] = true;
maxNum = max(maxNum, x);
}
}
///-------------------------------------
inline void Ciur()
{
for (int i = 2 ; 2 * i <= maxNum ; ++ i)
{
if (!ciur[i])
{
nr[i] = 1;
for (int j = 2 * i ; j <= maxNum ; j += i)
{
nr[j] ++;
ciur[j] = true;
if (j % (i * i) == 0) sqrd[j] = true;
}
}
}
}
///-------------------------------------
inline void Solve()
{
long long numPairs;
int dv;
ans = 1LL * N * (N - 1) / 2;
for (int i = 2 ; i <= maxNum ; ++ i)
{
if (sqrd[i]) continue;
dv = 0;
for (int j = i ; j <= maxNum ; j += i)
{
dv += freq[j];
}
numPairs = 1LL * dv * (dv - 1) / 2;
if (nr[i] % 2 == 1)
ans -= numPairs;
else
ans += numPairs;
}
}
///-------------------------------------
inline void Solution()
{
Ciur();
Solve();
}
///-------------------------------------
inline void Output()
{
g << ans;
}
///-------------------------------------
int main()
{
ReadInput();
Solution();
Output();
return 0;
}