Created
November 25, 2016 19:19
-
-
Save hkirat/c2feea3b78977a0feccca164a4c562f5 to your computer and use it in GitHub Desktop.
3^1000 in cpp
This file contains 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 <bits/stdc++.h> | |
using namespace std; | |
int a[1002]; | |
void multiply(int num) { | |
int c = 0; | |
for(int i =0 ; i<1002; i++) { | |
int temp = a[i]*num + c; | |
a[i] = temp%10; | |
c = temp/10; | |
} | |
} | |
int pow(int num, int p) { | |
for(int i = 0; i<p; i++) { | |
multiply(num); | |
} | |
int ans = 0; | |
bool f = false; | |
for(int i = 1002; i>=0; i--) { | |
if(!f && a[i]==0) { | |
continue; | |
} else { | |
f = true; | |
ans += a[i]; | |
} | |
} | |
return ans; | |
} | |
int main() | |
{ | |
a[0] = 1; | |
printf("%d\n", pow(3, 1000) ); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment