Pagini recente » Cod sursa (job #224305) | Cod sursa (job #2354813) | Cod sursa (job #2850248) | Cod sursa (job #2721675) | Cod sursa (job #1767316)
//fix 8
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int nmax=500,vmax=1000,lmax=1000000,cmax=30;
int n,in[nmax+5],npr,pr[nmax+5];
bool ci[nmax+5];
struct sp
{
char ch[cmax+5];
int len;
sp()
{
len=0;
for(int i=0;i<=cmax;i++)
ch[i]=0;
}
};
sp adun(sp a1,sp a2)
{
int i,l2=max(a1.len,a2.len);
sp ans;
for(i=1;i<=l2;i++)
{
ans.ch[i]+=a1.ch[i]+a2.ch[i];
if(ans.ch[i]>=10)
{
ans.ch[i]=ans.ch[i]-10;
ans.ch[i+1]++;
}
}
if(ans.ch[l2+1]>0)
l2++;
ans.len=l2;
// ans.len=l2;
return ans;
}
sp di[nmax+5][nmax+5];
long long 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;
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++)
di[i][j]=di[i-1][j];
di[i][in[i]]=adun(di[i][in[i]],unu);
for(j=1;j<=nmax;j++)
di[i][pre[in[i]][j]]=adun(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;
}