Take the 2-minute tour ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

Your task is to calculate the square root of a positive integer without using any mathematical operators to change the number, such as:

  • Setting a variable (ex. squareRoot = 5)
  • Addition (A+B)
  • Subtraction (A-B)
  • Multiplication (A*B)
  • Division (A/B)
  • Square, cube, fourth, etc. roots
  • Exponents

Comparison operators (such as <, >, ==, etc) are not considered "mathematical operators" for the purposes of this question and are allowed as long as they do not change the value of a variable.

The only operator that you are able to use is ++. The following exceptions are in place:

  • If you wish, you may initialize a variable by setting it to 0.
  • If your language does not include the ++ syntax, you may use an equivalent syntax, such as foo+=1 or foo=foo+1
  • The square root should be calculated to at least 6 digits beyond the decimal (the hundred-thousands place) and outputted as a whole number of the decimals (ex. if I input 2 it could come out as 14142135624 or 1414213 depending on the rounding). Rounding up or down is not important.

User-defined functions are not allowed. In addition, simulating functions with goto is not allowed as well.

I'm interested to see what everyone submits! Happy coding!

CLARIFICATION

Clarify that number is a positive integer. You are welcome to make code that would do any number but it is not necessary.

CLARIFICATION #2

Clarify that comparison operators are allowed.

CLARIFICATION #3

Addition, subtraction, multiplication, division, and functions to change numbers are not allowed at all, regardless of whether they are saved to a variable or not. I'm sorry that this invalidates a couple existing answers, but I meant to define this group of operators with "change the number" in order to prevent troll answers (ex. I just used the sqrt() function, you only prohibited addition, multiplication, division, and subtraction). Sorry for the confusion.

CLARIFICATION #4

Clarify that we need at least 5 digits. 10 digits caused code to run for a long time.

share|improve this question
    
Are comparisons such as < and > disallowed operators? –  Greg Hewgill Jun 6 at 2:06
    
Comparisons are fine, however the only operation that can change the value of a variable (or constant, I suppose) are ++ and --, with the exceptions listed above. –  iggyvolz Jun 6 at 2:07
1  
Nope, -- is not allowed, sorry for the confusion! I originally planned to have ++ and -- but I decided to take -- out at the last minute. –  iggyvolz Jun 6 at 2:15
4  
"without using any mathematical operators to change the number" - I think this might need clarification. Do you mean that these operators may not be used at all, or, that they may be used, but only if the result isn't saved to a variable, e.g. while r*r<n*10e20:r+=1 - fairly trivial. Also, you might consider reducing the required output to 10^8 or so. First, because 10^10 is larger than 2^31, and second, because it will take a while to increment that high. –  primo Jun 6 at 2:56
3  
I am flagging to close this question. To much radical changes to the question. You should actually get this question validated through Sandbox or else you would frustrate people investing effort to answer. –  Abhijit Jun 6 at 20:21
show 9 more comments

10 Answers 10

jQuery

jQuery is solution for everything!

var number = prompt("Provide a number");

// The element needs to exist in document to calculate its width.
$('body').append($('<div id="calculator_of_sorts">'));

// overflow: hidden is needed so the element would report real size.
$('#calculator_of_sorts').css('overflow', 'hidden');

var i;
for (i = 0; i < number; i++) {
    // Floats are the easiest way to put elements that only take
    // place for themselves.
    $('#calculator_of_sorts').append($('<div>').css('float', 'left').height(1).width(1));
}

try {
    // Bruteforce the solution
    i = 0;
    for (i++; i <= number; i++) {
        $('#calculator_of_sorts').width(i);
        if (i === $('#calculator_of_sorts').height()) {
            alert(i);
            break;
        }
    }
}
finally {
    // Clean the element after calculation. There is no need for
    // garbage to exist after calculation.
    $('#calculator_of_sorts').remove();
}
share|improve this answer
1  
What the hell? Does this work?? How??? –  Mark K Cowan Jun 7 at 14:19
    
works only for perfect sqares, can be easily modified to calculate floor(sqrt(x)) but most insane idea ever. +1 –  Valerij Jun 7 at 15:13
    
@MarkKCowan It fills a div with number 1-pixel divs. Then it sets one dimension of the parent div. The browser will reflow so the 1-pixel children still fit, which will change the other dimension. When the two dimensions are equal, it's a square, and the pixel length of the side is the square root of the area (1-pixel children). Only works for perfect squares, since it doesn't deal with fractional lengths. –  Bob Jun 7 at 15:15
    
You do know this is code golf, right? –  11684 Jun 7 at 16:01
1  
@11684: I'm aware, but this is not a serious entry. I even marked this answer as "community wiki" to not get upvotes from it. –  xfix Jun 7 at 18:30
show 3 more comments

Python 66

print'%.0f'%reduce(lambda a,b:abs(a)+1e10j,range(-2,input())).real

Output

>>> print'%.0f'%reduce(lambda a,b:abs(a)+1e10j,range(-2,input())).real
121
110000000000
>>> print'%.0f'%reduce(lambda a,b:abs(a)+1e10j,range(-2,input())).real
1000
316227766017

This solution uses Spiral of Theodorus on a complex plane to achieve the result.

share|improve this answer
2  
I think that will need to be wrapped in int(...*1e10), otherwise very nice. Although, taking abs of a complex value is more or less sqrt in disguise. –  primo Jun 6 at 9:16
1  
@primo I don't think you're allowed the *1e10 ... –  Cruncher Jun 6 at 14:54
    
@primo: Instead of multiplying by 1e10, I took a bit different route. And though I agree that abs may be sqrt in disguise, yet I feel its completely legal as currently stated in the problem. –  Abhijit Jun 6 at 15:13
    
I see a downvote, and its quite depressing. I had high hope for this answer, so any one who downvoted, please leave back a comment. –  Abhijit Jun 6 at 19:49
3  
@iggyvolz: I am really surprised that you keep on expanding your question and adding more restrictions. People invest time and effort to write an answer and you can;t expect them to be psycic. –  Abhijit Jun 6 at 20:19
show 3 more comments

Python, 184 characters

The following Python solution uses only the increment operator and no other arithmetic operators at all. However, with the required precision (10 digits), it takes an impossibly long time to run. You can test it with lower precision (3 digits) by reducing 1e20 to 1e6.

import sys;t=0
for _ in range(int(sys.argv[1])):
 for _ in range(int(1e20)):t+=1
q=0
while 1:
 z=0
 for _ in range(q):
  for _ in range(q):z+=1
 if z>=t:break
 q+=1
print(q)

Ungolfed:

import sys

# t = N * 100000000000000000000 (magnitude of twice the precision)
t = 0
for _ in range(int(sys.argv[1])):
    for _ in range(int(1e20)):
        t += 1
q = 0
while True:
    # z = q * q
    z = 0
    for _ in range(q):
        for _ in range(q):
            z += 1
    if z >= t:
        break
    q += 1
print(q)
share|improve this answer
    
I clarified the question, you can do it to as many digits as you want (at least 5). I'm not familiar with python, but I'm assuming that int() is just a type caster? If so, that is fine because it doesn't change the value of the number. –  iggyvolz Jun 6 at 20:13
    
@iggyvolz: Right, you need that to convert the string argument value (specified on the command line) to an integer. A plain function wouldn't need that. –  Greg Hewgill Jun 7 at 4:13
add comment

C - 161 143 137

Note: this is value*1e8, so it would be 138 bytes for value * 1e21. 10^20 wasn't tested as eight digits (four digits of precision in the result) was already taking a while to run.

edit: Reusing square result from previous loop for 100x speedup and 14 fewer bytes!

edit: 100000000 to 1e8 for six bytes!

Accepts a single command line argument and outputs the calculated square root for input value * 100,000,000

i=0,j,t,s;main(a,b)char**b;{s=atoi(b[1]);while(j=0,i++<1e8)while(j++<s)t++;for(s=i=0;s<t;j=0,i++,s++)while(j++<i)s++,s++;printf("%d",i);}

Ungolfed:

// uncomment to fix implicit declaration of printf
//#include <stdio.h>

i=0, j,    /* i,j are loop counters */
t,         /* t is target (input * 10^8) */
s;         /* s is the square and input value */

int main(a,b)char**b;
{
    // swap the implicit variable declarations with this line to fix warnings
    //int i=0,j,t,s;

    // read first command line argument and parse as int
    s=atoi(b[1]);

    // These two loops effectively multiple the target by 10^8.
    // The order of the conditions inside the first while() matters.
    // I wanted to declare i=1e8 and say while(j=0,i--) but oh well
    // Note:
    // Save three bytes at the cost of two orders of magnitude slowdown by replacing
    //     while(j++<s)
    // with
    //     while(j++<atoi(b[1]))
    // and commenting out the above line s=atoi(b[1]);
    while(j=0, i++<1e8)
        while(j++<s)
            t++;

    // This starts the counter (i) at 0 and squares each value. The
    // difference between successive squares (s) is the length of the side times
    // two, plus one. For example 3*3=9; the length of each side is 3; the
    // distance to the next square 16 is 3+3+1. The difference from 16 to
    // the next square 25 is 4+4+1, etc. The loop finishes when a calculated
    // square (s) is larger than the target (t).
    for(s=i=0; s<t; j=0, i++, s++)
        while(j++<i)
            s++, s++;

    printf("%d", i);

    // need a return value
    //return 0;
}

Sample run at 10^8, which is approximately four digits of precision on the calculated value:

$ time ./a.out 2
14143
real    0m0.871s
user    0m0.868s
sys     0m0.000s
share|improve this answer
    
You can golf this down to 135 fairly easily by reusing some variables and replacing while with for loops. –  ecatmur Jun 6 at 15:28
    
Good point on reusing variables, I dropped n and reused s. I'm not really seeing how to improve by changing to for loops though. –  tolos Jun 6 at 16:07
1  
So? while(j=0,i++<1e8)while(j++<s)t++; --> while(i++<1e8)for(j=0;j++<s;t++); –  edc65 Jun 6 at 19:19
add comment

Fortran 73

read*,t;s=0;do while(abs(s*s/1e10-t)>1e-10);s=s+1;enddo;print*,s/1e5;end

Might take a loooong to actually determine an answer for certain values, but it'll work for sure. While I use * and -, these are not changing any values, only the s=s+1 actually changes anything.

share|improve this answer
    
Wow, guess I didn't think about using operators for changing static values. That's perfectly fine and +1 (if I had 15 reputation to upvote) –  iggyvolz Jun 6 at 2:17
    
This uses the * operator, which is pretty clearly not permitted. Or am I somehow misunderstanding the given restrictions? –  Greg Hewgill Jun 6 at 2:20
    
@GregHewgill: OP states, without using any mathematical operators to change the number; these operators are not changing any values. –  Kyle Kanos Jun 6 at 2:21
6  
But that's still using the * operator to change a number, you're just not saving the result anywhere. If the OP wanted to simply disallow assignments (other than s=s+1), then why mention all the disallowed arithmetic operators? –  Greg Hewgill Jun 6 at 2:30
1  
@iggyvolz: Changing the rules ~20 hours later is bad form. Please do not do that and use the sandbox to work out the kinks in your problem instead. –  Kyle Kanos Jun 6 at 20:33
show 6 more comments

Javascript (61 chars)

function(n){for(i=0;Math.pow(i/1000000000,2)<n;++i);return i}

I would have happily made a version using only the ++ operator, but the following rule discouraged me from doing so.

User-defined functions are not allowed.

This solution exploits the fact that the rules are unclear about whether or not you can use mathetical operators if you're not modifying the input value.

without using any mathematical operators to change the number

share|improve this answer
5  
exponents are not allowed –  Lưu Vĩnh Phúc Jun 6 at 11:55
    
Division isn't either. –  Timtech Jun 6 at 14:55
    
He's got a point... he's never changing the number as the restriction specifies –  Mati Cicero Jun 6 at 17:03
    
This doesn't follow the new clarification. Sorry about invalidating your answer, but I meant to say that these functions were not allowed at all, not just to modify a variable. –  iggyvolz Jun 6 at 20:15
add comment

CJam, 26 bytes

q~,1e20,m*,:N!{)_,_m*,N<}g

Try it online. Paste the Code, type the desired integer in Input and click Run. Before you do, I suggest changing 1e10 to 1e4 though.

The Java interpreter handles 1e6 with input “2” in about 15 seconds. 1e20 will require a huge amount of RAM.

Examples

$ cjam <(echo 'q~,1e2,m*,:N!{)_,_m*,N<}g') <<< 4; echo
20
$ cjam <(echo 'q~,1e2,m*,:N!{)_,_m*,N<}g') <<< 2; echo
15
$ cjam <(echo 'q~,1e4,m*,:N!{)_,_m*,N<}g') <<< 4; echo
200
$ cjam <(echo 'q~,1e4,m*,:N!{)_,_m*,N<}g') <<< 2; echo
142
$ cjam <(echo 'q~,1e6,m*,:N!{)_,_m*,N<}g') <<< 4; echo
2000
$ cjam <(echo 'q~,1e6,m*,:N!{)_,_m*,N<}g') <<< 2; echo
1415

Background

Since we're not allowed mathematical operators to change numbers, we're going to use setwise operators to change arrays.

The code starts by "multiplying" the input (“i”) by 1e20, but without any actual multiplication. Instead, we push an array containing “i” integers, an array containing 1e20 integers, take their cartesian product and compute its length.

Then, we push zero and increment until the product of the integer by itself (calculated as above) is no longer smaller than i * 1e20. This causes the square root to be rounded up.

How it works

q~     " Read for STDIN and interpret. ";
,      " Push an array containing that many integers. ";
1e20,  " Push the array [ 0   …   1e20 - 1]. ";
m*,:N  " Get the length of the cartesian product and save it in “N”. ";
!      " Logical NOT. Since the input is a positive integer, this pushes 0. " ;
{      " ";
  )    " Increment the integer on the stack.";
  _,   " Push an array containing that many integers. ";
  _m*, " Get the length of the cartesian product of the array by itself. ";
  N<   " If the product is smaller than the target value, push 1; otherwise push 0. ";
}g     " Repeat the loop if the result was 1. ";
share|improve this answer
add comment

Cobra - 62

Posted before the third edit, no longer valid.

Not only is it short, but it should be overflow-free if n < Decimal.maxValue

def f(n)
    r,e=0d,10000000000
    while r/e*r/e<n,r+=1
    print r
share|improve this answer
    
But you used r/e*r/e, which is clearly a non-++ math operator... –  nneonneo Jun 8 at 2:19
    
@nneonneo this was posted before the third edit, and I haven't changed it yet –  Ourous Jun 8 at 3:28
add comment

Scala, 117

val z=BigInt(readLine+"0000000000")
print(Stream.from(1)find(x=>(BigInt(0)/:Stream.fill(x,x)(1).flatten){_+_}>=z)get)

Doesn't finish in a reasonable amount of time, even for 2 as input, but it does work. You may notice that I'm doing _+_, but that only ever adds 1, and Scala doesn't have a ++ operator anyway. I could save two characters by replacing the inner Stream with List, but then it would run out of memory. As written, I think it scales only in processing time, not memory usage.

share|improve this answer
add comment

The following Python program works for integers up to an maximum value of 999. A greater allowable input range is available upon request.

import sys
print([
0 ,
10000000000 ,
14142135623 ,
17320508075 ,
20000000000 ,
22360679774 ,
24494897427 ,
26457513110 ,
28284271247 ,
30000000000 ,
31622776601 ,
33166247903 ,
34641016151 ,
36055512754 ,
37416573867 ,
38729833462 ,
40000000000 ,
41231056256 ,
42426406871 ,
43588989435 ,
44721359549 ,
45825756949 ,
46904157598 ,
47958315233 ,
48989794855 ,
50000000000 ,
50990195135 ,
51961524227 ,
52915026221 ,
53851648071 ,
54772255750 ,
55677643628 ,
56568542494 ,
57445626465 ,
58309518948 ,
59160797830 ,
60000000000 ,
60827625302 ,
61644140029 ,
62449979983 ,
63245553203 ,
64031242374 ,
64807406984 ,
65574385243 ,
66332495807 ,
67082039324 ,
67823299831 ,
68556546004 ,
69282032302 ,
70000000000 ,
70710678118 ,
71414284285 ,
72111025509 ,
72801098892 ,
73484692283 ,
74161984870 ,
74833147735 ,
75498344352 ,
76157731058 ,
76811457478 ,
77459666924 ,
78102496759 ,
78740078740 ,
79372539331 ,
80000000000 ,
80622577482 ,
81240384046 ,
81853527718 ,
82462112512 ,
83066238629 ,
83666002653 ,
84261497731 ,
84852813742 ,
85440037453 ,
86023252670 ,
86602540378 ,
87177978870 ,
87749643873 ,
88317608663 ,
88881944173 ,
89442719099 ,
90000000000 ,
90553851381 ,
91104335791 ,
91651513899 ,
92195444572 ,
92736184954 ,
93273790530 ,
93808315196 ,
94339811320 ,
94868329805 ,
95393920141 ,
95916630466 ,
96436507609 ,
96953597148 ,
97467943448 ,
97979589711 ,
98488578017 ,
98994949366 ,
99498743710 ,
100000000000 ,
100498756211 ,
100995049383 ,
101488915650 ,
101980390271 ,
102469507659 ,
102956301409 ,
103440804327 ,
103923048454 ,
104403065089 ,
104880884817 ,
105356537528 ,
105830052442 ,
106301458127 ,
106770782520 ,
107238052947 ,
107703296142 ,
108166538263 ,
108627804912 ,
109087121146 ,
109544511501 ,
110000000000 ,
110453610171 ,
110905365064 ,
111355287256 ,
111803398874 ,
112249721603 ,
112694276695 ,
113137084989 ,
113578166916 ,
114017542509 ,
114455231422 ,
114891252930 ,
115325625946 ,
115758369027 ,
116189500386 ,
116619037896 ,
117046999107 ,
117473401244 ,
117898261225 ,
118321595661 ,
118743420870 ,
119163752878 ,
119582607431 ,
120000000000 ,
120415945787 ,
120830459735 ,
121243556529 ,
121655250605 ,
122065556157 ,
122474487139 ,
122882057274 ,
123288280059 ,
123693168768 ,
124096736459 ,
124498995979 ,
124899959967 ,
125299640861 ,
125698050899 ,
126095202129 ,
126491106406 ,
126885775404 ,
127279220613 ,
127671453348 ,
128062484748 ,
128452325786 ,
128840987267 ,
129228479833 ,
129614813968 ,
130000000000 ,
130384048104 ,
130766968306 ,
131148770486 ,
131529464379 ,
131909059582 ,
132287565553 ,
132664991614 ,
133041346956 ,
133416640641 ,
133790881602 ,
134164078649 ,
134536240470 ,
134907375632 ,
135277492584 ,
135646599662 ,
136014705087 ,
136381816969 ,
136747943311 ,
137113092008 ,
137477270848 ,
137840487520 ,
138202749610 ,
138564064605 ,
138924439894 ,
139283882771 ,
139642400437 ,
140000000000 ,
140356688476 ,
140712472794 ,
141067359796 ,
141421356237 ,
141774468787 ,
142126704035 ,
142478068487 ,
142828568570 ,
143178210632 ,
143527000944 ,
143874945699 ,
144222051018 ,
144568322948 ,
144913767461 ,
145258390463 ,
145602197785 ,
145945195193 ,
146287388383 ,
146628782986 ,
146969384566 ,
147309198626 ,
147648230602 ,
147986485869 ,
148323969741 ,
148660687473 ,
148996644257 ,
149331845230 ,
149666295470 ,
150000000000 ,
150332963783 ,
150665191733 ,
150996688705 ,
151327459504 ,
151657508881 ,
151986841535 ,
152315462117 ,
152643375224 ,
152970585407 ,
153297097167 ,
153622914957 ,
153948043183 ,
154272486205 ,
154596248337 ,
154919333848 ,
155241746962 ,
155563491861 ,
155884572681 ,
156204993518 ,
156524758424 ,
156843871413 ,
157162336455 ,
157480157480 ,
157797338380 ,
158113883008 ,
158429795177 ,
158745078663 ,
159059737205 ,
159373774505 ,
159687194226 ,
160000000000 ,
160312195418 ,
160623784042 ,
160934769394 ,
161245154965 ,
161554944214 ,
161864140562 ,
162172747402 ,
162480768092 ,
162788205960 ,
163095064303 ,
163401346383 ,
163707055437 ,
164012194668 ,
164316767251 ,
164620776331 ,
164924225024 ,
165227116418 ,
165529453572 ,
165831239517 ,
166132477258 ,
166433169770 ,
166733320005 ,
167032930884 ,
167332005306 ,
167630546142 ,
167928556237 ,
168226038412 ,
168522995463 ,
168819430161 ,
169115345252 ,
169410743460 ,
169705627484 ,
170000000000 ,
170293863659 ,
170587221092 ,
170880074906 ,
171172427686 ,
171464281994 ,
171755640373 ,
172046505340 ,
172336879396 ,
172626765016 ,
172916164657 ,
173205080756 ,
173493515728 ,
173781471969 ,
174068951855 ,
174355957741 ,
174642491965 ,
174928556845 ,
175214154679 ,
175499287747 ,
175783958312 ,
176068168616 ,
176351920885 ,
176635217326 ,
176918060129 ,
177200451466 ,
177482393492 ,
177763888346 ,
178044938147 ,
178325545001 ,
178605710994 ,
178885438199 ,
179164728671 ,
179443584449 ,
179722007556 ,
180000000000 ,
180277563773 ,
180554700852 ,
180831413200 ,
181107702762 ,
181383571472 ,
181659021245 ,
181934053986 ,
182208671582 ,
182482875908 ,
182756668824 ,
183030052177 ,
183303027798 ,
183575597506 ,
183847763108 ,
184119526395 ,
184390889145 ,
184661853126 ,
184932420089 ,
185202591774 ,
185472369909 ,
185741756210 ,
186010752377 ,
186279360101 ,
186547581061 ,
186815416922 ,
187082869338 ,
187349939951 ,
187616630392 ,
187882942280 ,
188148877222 ,
188414436814 ,
188679622641 ,
188944436276 ,
189208879284 ,
189472953214 ,
189736659610 ,
190000000000 ,
190262975904 ,
190525588832 ,
190787840283 ,
191049731745 ,
191311264697 ,
191572440606 ,
191833260932 ,
192093727122 ,
192353840616 ,
192613602842 ,
192873015219 ,
193132079158 ,
193390796058 ,
193649167310 ,
193907194296 ,
194164878389 ,
194422220952 ,
194679223339 ,
194935886896 ,
195192212959 ,
195448202856 ,
195703857907 ,
195959179422 ,
196214168703 ,
196468827043 ,
196723155729 ,
196977156035 ,
197230829233 ,
197484176581 ,
197737199332 ,
197989898732 ,
198242276015 ,
198494332412 ,
198746069143 ,
198997487421 ,
199248588451 ,
199499373432 ,
199749843554 ,
200000000000 ,
200249843945 ,
200499376557 ,
200748598998 ,
200997512422 ,
201246117974 ,
201494416796 ,
201742410018 ,
201990098767 ,
202237484161 ,
202484567313 ,
202731349327 ,
202977831301 ,
203224014329 ,
203469899493 ,
203715487874 ,
203960780543 ,
204205778566 ,
204450483002 ,
204694894904 ,
204939015319 ,
205182845286 ,
205426385841 ,
205669638012 ,
205912602819 ,
206155281280 ,
206397674405 ,
206639783197 ,
206881608655 ,
207123151772 ,
207364413533 ,
207605394920 ,
207846096908 ,
208086520466 ,
208326666559 ,
208566536146 ,
208806130178 ,
209045449603 ,
209284495364 ,
209523268397 ,
209761769634 ,
210000000000 ,
210237960416 ,
210475651798 ,
210713075057 ,
210950231097 ,
211187120819 ,
211423745118 ,
211660104885 ,
211896201004 ,
212132034355 ,
212367605815 ,
212602916254 ,
212837966537 ,
213072757526 ,
213307290077 ,
213541565040 ,
213775583264 ,
214009345590 ,
214242852856 ,
214476105895 ,
214709105535 ,
214941852602 ,
215174347913 ,
215406592285 ,
215638586528 ,
215870331449 ,
216101827849 ,
216333076527 ,
216564078277 ,
216794833886 ,
217025344142 ,
217255609824 ,
217485631709 ,
217715410570 ,
217944947177 ,
218174242292 ,
218403296678 ,
218632111090 ,
218860686282 ,
219089023002 ,
219317121994 ,
219544984001 ,
219772609758 ,
220000000000 ,
220227155455 ,
220454076850 ,
220680764907 ,
220907220343 ,
221133443874 ,
221359436211 ,
221585198061 ,
221810730128 ,
222036033111 ,
222261107708 ,
222485954612 ,
222710574513 ,
222934968096 ,
223159136044 ,
223383079036 ,
223606797749 ,
223830292855 ,
224053565024 ,
224276614920 ,
224499443206 ,
224722050542 ,
224944437584 ,
225166604983 ,
225388553391 ,
225610283453 ,
225831795812 ,
226053091109 ,
226274169979 ,
226495033058 ,
226715680975 ,
226936114358 ,
227156333832 ,
227376340018 ,
227596133534 ,
227815714997 ,
228035085019 ,
228254244210 ,
228473193175 ,
228691932520 ,
228910462845 ,
229128784747 ,
229346898823 ,
229564805664 ,
229782505861 ,
230000000000 ,
230217288664 ,
230434372436 ,
230651251893 ,
230867927612 ,
231084400165 ,
231300670124 ,
231516738055 ,
231732604525 ,
231948270094 ,
232163735324 ,
232379000772 ,
232594066992 ,
232808934536 ,
233023603954 ,
233238075793 ,
233452350598 ,
233666428910 ,
233880311270 ,
234093998214 ,
234307490277 ,
234520787991 ,
234733891886 ,
234946802489 ,
235159520326 ,
235372045918 ,
235584379787 ,
235796522451 ,
236008474424 ,
236220236220 ,
236431808350 ,
236643191323 ,
236854385646 ,
237065391822 ,
237276210354 ,
237486841740 ,
237697286480 ,
237907545067 ,
238117617995 ,
238327505756 ,
238537208837 ,
238746727726 ,
238956062906 ,
239165214862 ,
239374184071 ,
239582971014 ,
239791576165 ,
240000000000 ,
240208242989 ,
240416305603 ,
240624188310 ,
240831891575 ,
241039415863 ,
241246761636 ,
241453929352 ,
241660919471 ,
241867732448 ,
242074368738 ,
242280828791 ,
242487113059 ,
242693221990 ,
242899156029 ,
243104915622 ,
243310501211 ,
243515913237 ,
243721152139 ,
243926218353 ,
244131112314 ,
244335834457 ,
244540385212 ,
244744765010 ,
244948974278 ,
245153013442 ,
245356882927 ,
245560583156 ,
245764114548 ,
245967477524 ,
246170672501 ,
246373699895 ,
246576560118 ,
246779253585 ,
246981780704 ,
247184141886 ,
247386337537 ,
247588368062 ,
247790233867 ,
247991935352 ,
248193472919 ,
248394846967 ,
248596057893 ,
248797106092 ,
248997991959 ,
249198715887 ,
249399278266 ,
249599679486 ,
249799919935 ,
250000000000 ,
250199920063 ,
250399680510 ,
250599281722 ,
250798724079 ,
250998007960 ,
251197133741 ,
251396101799 ,
251594912508 ,
251793566240 ,
251992063367 ,
252190404258 ,
252388589282 ,
252586618806 ,
252784493195 ,
252982212813 ,
253179778023 ,
253377189186 ,
253574446662 ,
253771550808 ,
253968501984 ,
254165300542 ,
254361946839 ,
254558441227 ,
254754784057 ,
254950975679 ,
255147016443 ,
255342906696 ,
255538646783 ,
255734237050 ,
255929677841 ,
256124969497 ,
256320112359 ,
256515106767 ,
256709953059 ,
256904651573 ,
257099202643 ,
257293606605 ,
257487863791 ,
257681974534 ,
257875939164 ,
258069758011 ,
258263431402 ,
258456959666 ,
258650343127 ,
258843582110 ,
259036676939 ,
259229627936 ,
259422435421 ,
259615099714 ,
259807621135 ,
260000000000 ,
260192236625 ,
260384331325 ,
260576284415 ,
260768096208 ,
260959767013 ,
261151297144 ,
261342686907 ,
261533936612 ,
261725046566 ,
261916017074 ,
262106848441 ,
262297540972 ,
262488094968 ,
262678510731 ,
262868788561 ,
263058928759 ,
263248931621 ,
263438797446 ,
263628526529 ,
263818119165 ,
264007575648 ,
264196896272 ,
264386081328 ,
264575131106 ,
264764045897 ,
264952825989 ,
265141471671 ,
265329983228 ,
265518360947 ,
265706605111 ,
265894716006 ,
266082693913 ,
266270539113 ,
266458251889 ,
266645832519 ,
266833281282 ,
267020598456 ,
267207784317 ,
267394839142 ,
267581763205 ,
267768556779 ,
267955220139 ,
268141753555 ,
268328157299 ,
268514431641 ,
268700576850 ,
268886593194 ,
269072480941 ,
269258240356 ,
269443871706 ,
269629375254 ,
269814751264 ,
270000000000 ,
270185121722 ,
270370116691 ,
270554985169 ,
270739727413 ,
270924343682 ,
271108834234 ,
271293199325 ,
271477439209 ,
271661554144 ,
271845544381 ,
272029410174 ,
272213151776 ,
272396769437 ,
272580263408 ,
272763633939 ,
272946881279 ,
273130005674 ,
273313007374 ,
273495886623 ,
273678643668 ,
273861278752 ,
274043792120 ,
274226184016 ,
274408454680 ,
274590604354 ,
274772633280 ,
274954541697 ,
275136329843 ,
275317997958 ,
275499546279 ,
275680975041 ,
275862284482 ,
276043474836 ,
276224546338 ,
276405499221 ,
276586333718 ,
276767050061 ,
276947648482 ,
277128129211 ,
277308492477 ,
277488738510 ,
277668867538 ,
277848879788 ,
278028775489 ,
278208554864 ,
278388218141 ,
278567765543 ,
278747197295 ,
278926513619 ,
279105714739 ,
279284800875 ,
279463772249 ,
279642629082 ,
279821371592 ,
280000000000 ,
280178514522 ,
280356915377 ,
280535202782 ,
280713376952 ,
280891438103 ,
281069386451 ,
281247222208 ,
281424945589 ,
281602556806 ,
281780056072 ,
281957443597 ,
282134719593 ,
282311884269 ,
282488937836 ,
282665880502 ,
282842712474 ,
283019433961 ,
283196045170 ,
283372546306 ,
283548937575 ,
283725219182 ,
283901391331 ,
284077454226 ,
284253408071 ,
284429253066 ,
284604989415 ,
284780617317 ,
284956136975 ,
285131548587 ,
285306852353 ,
285482048472 ,
285657137141 ,
285832118559 ,
286006992921 ,
286181760425 ,
286356421265 ,
286530975637 ,
286705423736 ,
286879765755 ,
287054001888 ,
287228132326 ,
287402157263 ,
287576076890 ,
287749891398 ,
287923600977 ,
288097205817 ,
288270706107 ,
288444102037 ,
288617393793 ,
288790581563 ,
288963665535 ,
289136645896 ,
289309522829 ,
289482296522 ,
289654967159 ,
289827534923 ,
290000000000 ,
290172362570 ,
290344622819 ,
290516780926 ,
290688837074 ,
290860791444 ,
291032644217 ,
291204395571 ,
291376045686 ,
291547594742 ,
291719042916 ,
291890390386 ,
292061637330 ,
292232783924 ,
292403830344 ,
292574776766 ,
292745623366 ,
292916370317 ,
293087017795 ,
293257565972 ,
293428015022 ,
293598365118 ,
293768616431 ,
293938769133 ,
294108823397 ,
294278779391 ,
294448637286 ,
294618397253 ,
294788059459 ,
294957624075 ,
295127091267 ,
295296461204 ,
295465734053 ,
295634909981 ,
295803989154 ,
295972971738 ,
296141857899 ,
296310647800 ,
296479341607 ,
296647939483 ,
296816441593 ,
296984848098 ,
297153159162 ,
297321374946 ,
297489495612 ,
297657521322 ,
297825452236 ,
297993288515 ,
298161030317 ,
298328677803 ,
298496231131 ,
298663690461 ,
298831055949 ,
298998327754 ,
299165506033 ,
299332590941 ,
299499582637 ,
299666481275 ,
299833287011 ,
300000000000 ,
300166620396 ,
300333148353 ,
300499584026 ,
300665927567 ,
300832179129 ,
300998338865 ,
301164406927 ,
301330383466 ,
301496268633 ,
301662062579 ,
301827765455 ,
301993377410 ,
302158898594 ,
302324329156 ,
302489669245 ,
302654919008 ,
302820078594 ,
302985148150 ,
303150127824 ,
303315017762 ,
303479818109 ,
303644529013 ,
303809150619 ,
303973683071 ,
304138126514 ,
304302481094 ,
304466746952 ,
304630924234 ,
304795013082 ,
304959013639 ,
305122926047 ,
305286750449 ,
305450486986 ,
305614135798 ,
305777697028 ,
305941170815 ,
306104557300 ,
306267856622 ,
306431068920 ,
306594194335 ,
306757233003 ,
306920185064 ,
307083050655 ,
307245829914 ,
307408522978 ,
307571129984 ,
307733651068 ,
307896086366 ,
308058436014 ,
308220700148 ,
308382878902 ,
308544972410 ,
308706980808 ,
308868904229 ,
309030742807 ,
309192496674 ,
309354165965 ,
309515750810 ,
309677251344 ,
309838667696 ,
310000000000 ,
310161248385 ,
310322412983 ,
310483493925 ,
310644491340 ,
310805405358 ,
310966236109 ,
311126983722 ,
311287648325 ,
311448230047 ,
311608729017 ,
311769145362 ,
311929479209 ,
312089730686 ,
312249899919 ,
312409987036 ,
312569992161 ,
312729915422 ,
312889756943 ,
313049516849 ,
313209195267 ,
313368792319 ,
313528308131 ,
313687742827 ,
313847096529 ,
314006369362 ,
314165561448 ,
314324672910 ,
314483703870 ,
314642654451 ,
314801524773 ,
314960314960 ,
315119025131 ,
315277655408 ,
315436205911 ,
315594676761 ,
315753068076 ,
315911379978 ,
316069612585 ,
][int(sys.argv[1])])
share|improve this answer
1  
I knew I should have said "no hard-coding answers". Oh well, nice idea though! –  iggyvolz Jun 6 at 2:01
1  
13030 characters, I tagged it as an edit. You could remove the spaces and gain about 999 characters. I don't even know if this technically would count as a solution because it only works for the first 999 integers. –  iggyvolz Jun 6 at 2:03
    
Well, you didn't state in the question what the valid input consists of, so I guessed. Are positive integers the only valid inputs? –  Greg Hewgill Jun 6 at 2:05
    
Yes, positive integers are the only valid inputs. –  iggyvolz Jun 6 at 2:06
    
Yes, I tagged it as code-golf. Should I have made it more obvious in the question? –  iggyvolz Jun 6 at 2:10
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.