Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***
- created: 2022-07-05-03.46.15
- ***/
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- using namespace std;
- using namespace __gnu_pbds;
- template<typename U> using ordered_set=tree<U, null_type,less<U>,rb_tree_tag,tree_order_statistics_node_update>;
- #define ll long long
- #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
- #define get_lost_idiot return 0
- #define nl '\n'
- ll bigmod(ll a,ll c,ll d)
- {
- ll ans=1ll;
- while(c>0)
- {
- if(c&1) ans=(ans*a)%d;
- a=(a*a)%d;
- c>>=1;
- }
- return ans;
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- test
- {
- ll n,m,i,j,k,l,p;
- cin>>n>>p;
- if(n>=p)
- {
- cout<<0<<nl;
- }
- else
- {
- ll ans=p-1;
- for(i=n+1;i<p;i++)
- {
- ans*=bigmod(i,p-2,p);
- ans%=p;
- }
- cout<<(ans+p)%p<<nl;
- }
- }
- get_lost_idiot;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement