Skip to content

Instantly share code, notes, and snippets.

@hkirat
Created November 25, 2016 19:19
Show Gist options
  • Save hkirat/c2feea3b78977a0feccca164a4c562f5 to your computer and use it in GitHub Desktop.
Save hkirat/c2feea3b78977a0feccca164a4c562f5 to your computer and use it in GitHub Desktop.
3^1000 in cpp
#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