Pagini recente » Cod sursa (job #1917772) | Cod sursa (job #2025799) | Cod sursa (job #851248) | Cod sursa (job #2295537) | Cod sursa (job #1657493)
#include <stdio.h>
#include <algorithm>
using namespace std;
struct bigint
{
int t[500];
bigint()
{
for (int i=0;i<500;i++) t[i]=0;
}
void init() { t[0]=1; }
void print()
{
for (int i=t[0];i>=1;i--) printf("%d ",t[i]);
printf("\n");
}
};
int n,nr;
int t[510];
bigint v,dp[510][1010];
inline int gcd(int a,int b)
{
if (b==0) return a; else
return gcd(b,a%b);
}
bigint operator + (bigint &a,bigint &b)
{
bigint c; int r=0; c.t[0]=max(a.t[0],b.t[0]);
for (int i=1;i<=c.t[0];i++) {
c.t[i]=(a.t[i]+b.t[i]+r)%10; r=(a.t[i]+b.t[i]+r)/10;
}
if (r>0) c.t[0]++,c.t[c.t[0]]=r;
return c;
}
int main()
{
freopen("indep.in","r",stdin);
freopen("indep.out","w",stdout);
scanf("%d",&n);
for (int i=1;i<=n;i++) scanf("%d",&t[i]);
for (int i=0;i<=n;i++)
for (int j=1;j<=1000;j++)
dp[i][j].init();
v.t[0]=v.t[1]=1;
for (int i=1;i<=n;i++) {
for (int j=1;j<=1000;j++) {
dp[i][j]=dp[i][j]+dp[i-1][j];
dp[i][gcd(j,t[i])]=dp[i][gcd(j,t[i])]+dp[i-1][j];
}
dp[i][t[i]]=v+dp[i][t[i]];
}
dp[n][1].print();
return 0;
}