Pagini recente » Cod sursa (job #3173952) | Cod sursa (job #2283302) | Statistici emperor (emperorofheaven) | Cod sursa (job #335540) | Cod sursa (job #6592)
Cod sursa(job #6592)
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
using namespace std;
typedef short lnum[240];
const int maxn = 1001;
const int maxn2 = 501;
short j;
lnum mat[maxn],aux[maxn];
short a[maxn];
short i;
lnum s;
short n;
short max(short a,short b)
{
if (a<b) return b;
return a;
}
void ad(lnum &a,lnum &b,lnum &c)
{
int i;
a[0]=max(b[0],c[0]);
for(i=1;i<=max(b[0],c[0]);i++)
{
a[i]=c[i]+b[i];
}
for(i=1;i<=a[0];i++)
{
if (a[i]>=10)
{
a[i]%=10;
a[i+1]++;
if (a[a[0]+1]>0) a[0]++;
}
}
}
/*
void add(lnum a, lnum b, lnum c)
{
int i, t = 0;
for(i = 1; i <= a[0] || i <= b[0] || t; ++ i) {
c[i] = a[i]+b[i]+t;
t = c[i]/10;
c[i] %= 10;
}
c[0] = i-1;
}
*/
short cmmdc(short a, short b)
{
while (a)
{
short aux=a;
a=b%a;
b=aux;
}
return b;
}
int main()
{
freopen("indep.in","r",stdin);
freopen("indep.out","w",stdout);
scanf("%hd",&n);
for(i=1;i<=n;i++)
{
short x;
scanf("%hd",&a[i]);
}
short x;
s[1]=1;
s[0]=1;
ad(mat[a[1]],mat[a[1]],s);
memcpy(aux,mat,sizeof(mat));
// memset(mat,0,sizeof(mat));
for(i=2;i<=n;i++)
{
ad(mat[a[i]],mat[a[i]],s);
/* for(j=1;j<=1000;j++)
ad(mat[j],mat[j],aux[j]);*/
for(j=1000;j>0;j--)
if (aux[j][0]!=0)
{
x=cmmdc(j,a[i]);
ad(mat[x],mat[x],aux[j]);
}
memcpy(aux,mat,sizeof(mat));
//memset(mat,0,sizeof(mat));
}
if (aux[1][0]==0) printf("0");
for(i=aux[1][0];i>0;i--)
printf("%hd",aux[1][i]);
printf("\n");
return 0;
}