Pagini recente » Cod sursa (job #2378406) | Cod sursa (job #2332706) | Cod sursa (job #2791659) | Cod sursa (job #2387862) | Cod sursa (job #1767905)
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int nmax=500,vmax=1000,cmax=20,base=1000000000;
int n,in[nmax+5],npr,pr[nmax+5];
bool ci[nmax+5];
struct sp
{
int ch[cmax+5];
int len;
sp()
{
len=1;
for(int i=0;i<cmax;i++)
ch[i]=0;
}
const sp operator + (const sp & other)const
{
int i,l2=max(len,other.len);
sp ans;
for(i=1;i<=l2;i++)
{
ans.ch[i]+=ch[i]+other.ch[i];
if(ans.ch[i]>base)
{
ans.ch[i+1]++;
ans.ch[i]-=base;
}
}
if(ans.ch[l2+1]>0)
l2++;
if(l2==cmax-1)
printf("%d\n",l2%0);
ans.len=l2;
return ans;
}
};
sp di[5][vmax+5];
int pre[vmax+5][vmax+5];
int cmmdc(int a,int b)
{
if(a>b)
swap(a,b);
if(a==0)
return b;
return cmmdc(b%a,a);
}
int main()
{
freopen("indep.in","r",stdin);
freopen("indep.out","w",stdout);
int m,i,j,x,p;
long long ans=0;
sp unu;
unu.ch[1]=1;
unu.len=1;
cin>>n;
for(i=1;i<=n;i++)
cin>>in[i];
for(i=0;i<=vmax;i++)
for(j=0;j<=vmax;j++)
pre[i][j]=cmmdc(i,j);
for(i=1;i<=n;i++)
{
p=2;
for(j=1;j<=vmax;j++)
{
di[p][j].len=di[p-1][j].len;
for(x=di[p][j].len;x>=1;x--)
di[p][j].ch[x]=di[p-1][j].ch[x];
}
di[p][in[i]]=di[p][in[i]]+unu;
for(j=1;j<=vmax;j++)
if(!(di[p-1][j].len==1 && di[p-1][j].ch[1]==0))
di[p][pre[in[i]][j]]=di[p][pre[in[i]][j]]+di[p-1][j];
for(j=1;j<=vmax;j++)
di[p-1][j]=di[p][j];
}
for(i=di[p][1].len;i>=1;i--)
if(i==di[p][1].len)
printf("%d",di[p][1].ch[i]);
else
printf("%.9d",di[p][1].ch[i]);
printf("\n");
return 0;
}