Pagini recente » Cod sursa (job #1683792) | Cod sursa (job #410949) | Cod sursa (job #443347) | Cod sursa (job #1512743) | Cod sursa (job #3130218)
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int NMAX = 502;
const int VMAX = 1002;
const int CMAX = 5002;
int n,a[NMAX],vf[VMAX],f[VMAX],cnt[VMAX],nr1;
/// vf[i] = cate nr sunt divizibile cu i
/// cate subsiruri care au cmmdc i = 2^vf[i]
/// ans = (# total de subsiruri) - (# de subsiruri cu cmmdc != 1)
/// f[i] = 0 daca i e liber de patrat
/// 1 caz contrar
/// cnt[i] = nr de factori primi din descompunere
typedef int NrMare[CMAX];
NrMare unu,ans,pwr;
ifstream fin("indep.in");
ofstream fout("indep.out");
void mult(NrMare x, int n){
/// x = x*n
int transport = 0;
for(int i = 1; i <= x[0]; i++){
transport += x[i]*n;
x[i] = transport%10;
transport /= 10;
}
while(transport){
x[++x[0]] = transport%10;
transport /= 10;
}
}
void adun(NrMare a, NrMare b){
/// a = a+b
int transport = 0;
for(int i = 1; i <= a[0]; i++){
transport += a[i]+b[i];
a[i] = transport%10;
transport /= 10;
}
while(transport){
a[++a[0]] = transport%10;
transport /= 10;
}
}
void scad(NrMare a, NrMare b){
/// a = a-b
for(int i = b[0]+1; i <= a[0]; i++){
b[i] = 0;
}
int transport = 0;
for(int i = 1; i <= a[0]; i++){
a[i] = a[i]-(b[i]+transport);
if(a[i] < 0){
transport = 1;
}else{
transport = 0;
}
if(transport){
a[i] += 10;
}
}
while(a[0] > 1 && a[a[0]] == 0){
a[0]--;
}
}
void afis(NrMare a){
for(int i = a[0]; i >= 1; i--){
fout << a[i];
}
}
signed main()
{
for(int i = 2; i < VMAX; i++){
if(cnt[i] == 0){
cnt[i]++;
for(int j = i+i; j < VMAX; j += i){
cnt[j]++;
}
for(int j = i; j < VMAX/i; j += i){
f[j*i] = 1;
}
}
}
fin >> n;
for(int i = 1; i <= n; i++){
fin >> a[i];
for(int d = 1; d*d <= a[i]; d++){
if(a[i]%d == 0){
vf[d]++;
if(d != a[i]/d){
vf[a[i]/d]++;
}
}
}
}
unu[0] = unu[1] = ans[0] = ans[1] = 1;
for(int i = 1; i <= n; i++){
mult(ans, 2);
}
scad(ans, unu);
for(int i = 2; i < VMAX; i++){
if(!f[i]){
if(vf[i] > 0){
if(cnt[i]%2 == 0){
memset(pwr, 0, sizeof(pwr));
pwr[0] = pwr[1] = 1;
for(int j = 1; j <= vf[i]; j++){
mult(pwr, 2);
}
scad(pwr, unu);
adun(ans, pwr);
}
}
}
}
for(int i = 2; i < VMAX; i++){
if(!f[i]){
if(vf[i] > 0){
if(cnt[i]%2 == 1){
memset(pwr, 0, sizeof(pwr));
pwr[0] = pwr[1] = 1;
for(int j = 1; j <= vf[i]; j++){
mult(pwr, 2);
}
scad(pwr, unu);
scad(ans, pwr);
}
}
}
}
afis(ans);
return 0;
}