Pagini recente » Cod sursa (job #1076294) | Cod sursa (job #774825) | Cod sursa (job #1717614) | Cod sursa (job #984324) | Cod sursa (job #2226192)
#include <fstream>
using namespace std;
ifstream fin("indep.in");
ofstream fout("indep.out");
class big
{
private :
int cif[37];
short int len;
public :
void operator = (const int &other)
{
int aux=other;
len=0;
while(aux)
{
cif[++len]=aux%1000000000;
aux/=1000000000;
}
}
void operator += (const big &other)
{
big ans;
int i=1,rezid=0,sum;
for(i=1;i<=len || i<=other.len || rezid>0;i++)
{
sum=rezid;
if(i<=len)
sum+=cif[i];
if(i<=other.len)
sum+=other.cif[i];
ans.cif[i]=sum%1000000000;
rezid=sum/1000000000;
}
ans.len=i-1;
len=ans.len;
for(int i=1;i<=len;i++)
cif[i]=ans.cif[i];
}
void afis ()
{
for(int i=len;i>=1;i--)
fout<<cif[i];
}
};
const int N=500+1;
const int L=1000+1;
big dp[N][L];
int gcd[L][L];
int main()
{
for(int i=1;i<L;i++)
{
gcd[1][i]=gcd[i][1]=1;
gcd[i][i]=i;
}
for(int i=2;i<L;i++)
for(int j=2;j<i;j++)
gcd[i][j]=gcd[j][i]=gcd[i-j][j];
big v1; v1=1;
int n;
fin>>n;
for(int i=1;i<=n;i++)
{
int foo;
fin>>foo;
dp[i][foo]+=v1;
for(int j=1;j<L;j++)
{
int val=gcd[j][foo];
dp[i][j]+=dp[i-1][j];
dp[i][val]+=dp[i-1][j];
}
}
dp[n][1].afis();
return 0;
}
/**
**/