Pagini recente » Cod sursa (job #967727) | Cod sursa (job #2157870) | Cod sursa (job #543590) | Cod sursa (job #949028) | Cod sursa (job #2226189)
#include <fstream>
using namespace std;
ifstream fin("indep.in");
ofstream fout("indep.out");
const int ROFLAN=1000000000;
///const int ROFLAN=100;
class big
{
private :
int cif[20];
int len;
public :
void operator = (const int &other)
{
int aux=other;
len=0;
while(aux)
{
cif[++len]=aux%ROFLAN;
aux/=ROFLAN;
}
}
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%ROFLAN;
rezid=sum/ROFLAN;
}
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()
{
big v1; v1=1;
/** big a; a=0;
for(int i=1;i<=1000;i++)
{
a+=v1;
a.afis();
fout<<"\n";
}
return 0;**/
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];
int n;
fin>>n;
for(int i=1;i<=n;i++)
{
int foo;
fin>>foo;
for(int j=1;j<L;j++)
dp[i][j]=dp[i-1][j];
dp[i][foo]+=v1;
for(int j=1;j<L;j++)
{
dp[i][gcd[j][foo]]+=dp[i-1][j];
}
}
dp[n][1].afis();
fout<<"\n";
return 0;
}
/**
**/