Pagini recente » Cod sursa (job #172240) | Cod sursa (job #3132924) | Cod sursa (job #357138) | Cod sursa (job #2266192) | Cod sursa (job #238809)
Cod sursa(job #238809)
#include<stdio.h>
int v[2500011],a[2500011],d;
unsigned long long int r,nr,i,j,k;
int main(){
FILE *f=fopen("pascal.in","r");
fscanf(f,"%lld %d",&r,&d);
fclose(f);
FILE *g=fopen("pascal.out","w");
a[1]=1;i=2;k=2;
if(r==1||r==2)
fprintf(g,"%lld",0);
else
while(1)
{for(j=1;j<=k/2;j++)
v[j]=(a[j-1]+a[j])%d;
v[k/2+1]=2*a[k/2]; k++;
if(k==r+1)
{for(i=1;i<k/2;i++)
if(v[j]%d==0)nr++;
nr*=2;
if(v[k/2+1]%d==0)nr++;
fprintf(g,"%lld",nr);
fclose(g);
return 0;}
for(i=1;i<=k/2+1;i++)
a[i]=(v[i-1]+v[i])%d;
k++;
if(k==r+1)
{for(j=1;j<=k/2;j++)
if(a[j]%d==0)nr++;
fprintf(g,"%lld",nr*2);
fclose(g);
return 0;
}
}
fclose(g);
return 0;}