Created
November 25, 2016 19:18
-
-
Save hkirat/2bd1b6326990bb7f7ce17cf79a4d52cb to your computer and use it in GitHub Desktop.
3^1000 in js
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
function findPower(num, p) { | |
var ans = []; | |
var ret = 0; | |
ans.push(1); | |
for(var i = 0; i<p; i++) { | |
var c = 0; | |
for(var j = 0; j<ans.length; j++) { | |
ans[j]*=num; | |
ans[j]+=c; | |
c = parseInt(ans[j]/10); | |
ans[j] = ans[j]%10; | |
} | |
while(c!=0) { | |
ans.push(c%10); | |
c = parseInt(c/10); | |
} | |
} | |
for(var i = 0; i<ans.length; i++) { | |
ret+=ans[i]; | |
} | |
return ret; | |
} | |
console.log(findPower(3, 1000)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment