Advertisement
a53

NMult

a53
Dec 8th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include<stdio.h>
  2. using namespace std;
  3. long n,k,w,H=666013,r;
  4. long long m,z,p,x,y,t,xx,yy,i;
  5. char a[1000010];
  6. int main(){
  7. freopen("nmult.in","r",stdin);
  8. freopen("nmult.out","w",stdout);
  9. scanf("%ld%ld%ld",&n,&k,&w);
  10. m=n-(k-1)*(w-1);
  11. xx=k; yy=m-k;
  12. if (xx<yy){xx=m-k; yy=k;}
  13. z=1;
  14. for (p=2;p<=m;p++){
  15. if (a[p]==0){
  16. for (i=p*p;i<=m;i=i+p)
  17. a[i]=1;
  18. x=xx; y=yy;
  19. t=0;
  20. while(x){
  21. t=(t+x%p+y%p)/p;
  22. if(t!=0) z=(z*p)%H;
  23. x=x/p;
  24. y=y/p;
  25. }
  26. }
  27. }
  28. r=z;
  29. if (m<k) printf("0\n");
  30. else printf("%ld\n",r);
  31. fclose(stdout);
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement