Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // sir-Em O(n)
- #include <fstream>
- using namespace std;
- #define M 20173333
- int a[131072];
- int inv(long long x)
- {long long p=1,n=M-2;
- while (n>0)
- { if (n%2==1)
- { p=(p*x)%M; n--;}
- else
- { x=(x*x)%M; n/=2;}
- }
- return p;
- }
- int main()
- {
- ifstream fi("sir9.in"); ofstream fo("sir9.out");
- int n,u,i,p;
- long long r,t;
- fi>>p;
- fi>>n>>u;
- if(p==1)
- { /*
- a[0]=1; // triunghiul lui Pascal
- for(i=1;i<n;i++)
- { a[i]=1;
- for(j=i-1;j>=0;j--)
- a[j]=(a[j]+a[j-1])%M;
- }
- fo<<a[u-1]<<"\n";
- */
- for(r=1,i=2;i<n;i++)
- r=(r*i)%M;
- for(t=1,i=2;i<u;i++)
- t=(t*i)%M;
- r=(r*inv(t))%M;
- for(t=1,i=2;i<=n-u;i++)
- t=(t*i)%M;
- r=(r*inv(t))%M;
- fo<<r<<"\n";
- }
- else
- { a[1]=1;
- r=(n==u);
- for(i=2;i<=n;i++)
- { if(i>u) t=a[i-1]+M-a[i-u-1];
- else t=a[i-1];
- a[i]=(a[i-1]+t)%M;
- if(i>=n-u+1) r=(r+t)%M;
- }
- fo<<r<<"\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement