Created
February 7, 2015 19:50
-
-
Save shohan4556/f3513da475d9b9b1ff27 to your computer and use it in GitHub Desktop.
UVA 10127 solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include<stdio.h> | |
| int long long bigmod(int long long a ,int p,int m); | |
| int main() | |
| { | |
| int long long a; | |
| int long long p,m,n,t; | |
| int c; | |
| while(scanf("%lld",&n)==1){ | |
| c=1; | |
| t=10; | |
| a=1; | |
| while(a%n!=0){ | |
| a=a*t+1; | |
| c++; | |
| a=bigmod(a,1,n); | |
| } | |
| printf("%d\n",c); | |
| } | |
| return 0; | |
| } | |
| int long long bigmod(int long long a ,int p,int m) | |
| { | |
| if(p==0) | |
| return 1; | |
| if(p%2==0){ // p is even then split it up and mod | |
| int c=bigmod(a,p/2,m); | |
| return ( (c%m) * (c%m) )%m; | |
| } | |
| else // p is odd then make it even | |
| return ( (a%m)* bigmod(a,p-1,m) ) %m; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment