Skip to content

Commit

Permalink
Merge pull request #35 from Shashwat-Garg/master
Browse files Browse the repository at this point in the history
Modular GCD
  • Loading branch information
ows-ali authored Oct 19, 2018
2 parents 1328502 + 63681ab commit 51f9349
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Codechef/GCDMOD.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Shashwat Garg
* B16034
* IIT Mandi
*/

def gcd(a,b):
if(b==0):
return a
return gcd(b,a%b)
t=input();
for i in range(t):
a,b,n=map(int,raw_input().split())
if(a==b):
res=pow(a,n,1000000007)
res=res+pow(b,n,1000000007)
res=res%(1000000007)
print res
continue
res=pow(a,n,a-b)
res=res+pow(b,n,a-b)
res=res%(a-b)
print gcd(a-b,res)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ In this repository, you can find the solutions (as source code) for the problems
| [codingCookie](https://github.com/codingCookie) <br> <img src="https://github.com/codingCookie.png" width="100" height="100"> | Germany | | |
| [Keshav Bansal](https://github.com/keshavx11) <br> <img src="https://github.com/keshavx11.png" width="100" height="100"> | India | | |
| [Advaya Andhare](https://github.com/advaya08) <br> <img src="https://github.com/advaya08.png" width="100" height="100"> | India | C++ | |
| [Shashwat Garg](https://github.com/Shashwat-Garg) <br> <img src="https://github.com/Shashwat-Garg.png" width="100" height="100"> | India | Python | |


### License
Expand Down

0 comments on commit 51f9349

Please sign in to comment.