Pagini recente » Cod sursa (job #517484) | Cod sursa (job #278672) | Cod sursa (job #1958607) | Cod sursa (job #396998) | Cod sursa (job #1767338)
//fix 8
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int nmax=500,vmax=1000,cmax=500;
int n,in[nmax+5],npr,pr[nmax+5];
bool ci[nmax+5];
struct sp
{
char 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]>9)
{
ans.ch[i+1]++;
ans.ch[i]-=10;
}
}
if(ans.ch[l2+1]>0)
l2++;
ans.len=l2;
return ans;
}
};
sp di[nmax+5][nmax+5];
int pre[nmax+5][nmax+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;
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<=nmax;i++)
for(j=0;j<=nmax;j++)
pre[i][j]=cmmdc(i,j);
for(i=1;i<=n;i++)
{
for(j=1;j<=nmax;j++)
{
for(x=di[i-1][j].len;x>=1;x--)
di[i][j].ch[x]=di[i-1][j].ch[x];
di[i][j].len=di[i-1][j].len;
}
di[i][in[i]]=di[i][in[i]]+unu;
for(j=1;j<=nmax;j++)
if(!(di[i-1][j].len==1 && di[i-1][j].ch[1]==0))
di[i][pre[in[i]][j]]=di[i][pre[in[i]][j]]+di[i-1][j];
}
for(i=di[n][1].len;i>=1;i--)
printf("%d",di[n][1].ch[i]);
printf("\n");
return 0;
}