-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Computing a raised to b mod c in logn time #108
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include<bits/stdc++.h> | ||
#define MOD 1000000007 | ||
#define MOD9 1000000009 | ||
#define forr(i,p,n) for(ll i=p;i<n;i++) | ||
#define endl "\n" | ||
typedef long long ll; | ||
using namespace std; | ||
|
||
ll fast_power(ll n, ll k, ll p = MOD) { | ||
ll r = 1; | ||
for (; k; k >>= 1) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra space |
||
if (k & 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 4 line space after bracket. |
||
{ | ||
r = r * n%p; | ||
} | ||
n = n * n%p; | ||
} | ||
return r; | ||
} | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No space required. |
||
int main(){ | ||
ios::sync_with_stdio(0); | ||
cin.tie(0);cout.tie(0); | ||
ll a,b,c; | ||
cin>>a>>b>>c; | ||
ll ans=fast_power(a,b,c); | ||
cout<<ans<<endl; | ||
return 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra space |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No indentation.