Code: Select all
x = ((17**39)**11).to_s
result = ''
(x.size/33).times {|t|result<<x[t*33,1]}
p result
Code: Select all
x = ((17**39)**11).to_s
result = ''
(x.size/33).times {|t|result<<x[t*33,1]}
p result
Code: Select all
n = (17 ** 39) ** 11
print str(n)[::33]
Code: Select all
x = str(((17**39)**11))
x2 = ''
for i in range(0,len(x),33):
x2 += x[i]
print 'powers that be ', x2
Code: Select all
use bignum;
$r = ((17 ** 39) ** 11);
for ($i = 0; $i < length($r); $i += 33) {
print substr($r,$i,1);
}
print "\n";
Code: Select all
#include <iostream>
using namespace std;
string add(string augend,string addend){ //funktioniert nur für positive ganzzahlen
int i,j,k,s1,s2,sum,uber=0;
string str,result="";
i=augend.length()-1;
j=addend.length()-1;
if (i>=j){
k=i;
}
else{
k=j;
}
while (k>=0){
if (i>=0){
s1=augend.at(i)-48;
}
else{
s1=0;
}
if (j>=0){
s2=addend.at(j)-48;
}
else{
s2=0;
}
sum=s1 + s2 + uber + 48;
if (s1+s2+uber>=10){
uber=1;
sum=sum-10;
if (k==0){
k++;
}
}
else{
uber=0;
}
str=sum;
result=result.insert(0,str);
i--;j--;k--;
}
return(result);
}
string multi(string multiplicand,string multiplier){
string str_counter="0",result="";
while (str_counter.compare(multiplier) != 0){
result=add(multiplicand,result);
str_counter=add(str_counter,"1");
}
return(result);
}
string power(string base,string exponent){
string str_counter="1",result=base;
while (str_counter.compare(exponent) != 0){
result=multi(result,base);
str_counter=add(str_counter,"1");
}
return(result);
}
int main(){
string str1="17",str2="429",str3;
str3=power(str1,str2);
cout << str3 << endl;
for (int i=1;i<=str3.length()/33;i++){
cout << str3.at(33*i-33);
}
}
And I know now how to do it in PHP.DocJoe wrote:Nice challenge. Now I know how to do large number multiplication in python.
Code: Select all
$x = bcpow(bcpow(17, 39), 11);
for($i = 0; $i < strlen($x); $i++) {
echo $x[$i];
if(($i+1) % 33 == 0) echo "<br />";
}
python FTWgfoot wrote:You don't need to import anything fancy to work with large integers - just write the expression as normal. Python silently switches types to a flexible type when the numbers get too large for a normal integer.
Code: Select all
n = (17 ** 39) ** 11 print str(n)[::33]
Code: Select all
#!/bin/python
a = (17 ** 39) ** 11
count = count + a[0]
for i in range(0, len(a)):
if i % 33 == 0:
count = count + a[i]
print count