Alternate way of Squaring a Number












0














I came up with this technique a few years ago. It seems to be working fine.



Input: a number



Output: Its' square



x=int(input("Enter the number whose square you wish to find out: "))  #decimal input invalid
last_digit=x%10
#We will use formula Sn= (n/2)*(2a+ (n-1)d) of AP
a=100 + last_digit*20 #100,20 are fixed values
d=200 #200 is a fixed value
n=(x-last_digit)/10

final_answer=(n/2)*(2*a + (n-1)*d) + last_digit**2 #These calculations are easier than x*x for a vvlarge x
#normal multiplication is d*d digits, but this is d*(d-1) or d*(d-2) digits

print("My answer: " ,format(final_answer,'f'))
print("Actual answer: ", x**2)


I have written comments to indicate what Im doing at each step



-> How does this work? Like seriously? I got this by observing some patterns and generalising them
-> This code was meant to work only for 3-digit numbers, but it works for all numbers. How?



By expanding/substitution, my 'derivation' is as follows:-



NOTE: L=last_digit



n = (x-L)/10 #The same thing as n=x//10



a = 100 + 20L



d = 200



Our final answer is:-



=> (n/2) * (2a + (n-1)d ) + L^2



Substituting values for the variables,



=> [(x-L)/20] * [200 + 40L + [(x-L)/10]*200 - 200] + L^2



Taking the 20 in [(x-L)/20] and taking it to the RHS of * sign,



=> (x-L) * [10 + 2L + x - L -10] + L^2



=> (x-L)*(x+L) + L^2



=> x^2 - L^2 + L^2



=> x^2










share|improve this question
























  • Expand the terms and simplify. You'll end up with x^2. It's tedious but straightforward.
    – user2357112
    Nov 19 '18 at 18:32










  • It may help to express n as (x-last_digit)/10.
    – user2357112
    Nov 19 '18 at 18:33










  • Yes, I got x^2 in the end. @user2357112
    – Prabhat Soni
    Nov 21 '18 at 18:53










  • Is there some past mathematical theorem about this, or why this works or is this just a coincidence that this works?
    – Prabhat Soni
    Nov 21 '18 at 19:16










  • How big are the numbers you've tested this with? I think that for very big numbers (the only ones alternative squaring arrangements would help with), you should start to be worried about the imprecision of the floating point numbers introducing error. (Or just trying to store a too large number)
    – Patrick Haugh
    Nov 21 '18 at 19:36
















0














I came up with this technique a few years ago. It seems to be working fine.



Input: a number



Output: Its' square



x=int(input("Enter the number whose square you wish to find out: "))  #decimal input invalid
last_digit=x%10
#We will use formula Sn= (n/2)*(2a+ (n-1)d) of AP
a=100 + last_digit*20 #100,20 are fixed values
d=200 #200 is a fixed value
n=(x-last_digit)/10

final_answer=(n/2)*(2*a + (n-1)*d) + last_digit**2 #These calculations are easier than x*x for a vvlarge x
#normal multiplication is d*d digits, but this is d*(d-1) or d*(d-2) digits

print("My answer: " ,format(final_answer,'f'))
print("Actual answer: ", x**2)


I have written comments to indicate what Im doing at each step



-> How does this work? Like seriously? I got this by observing some patterns and generalising them
-> This code was meant to work only for 3-digit numbers, but it works for all numbers. How?



By expanding/substitution, my 'derivation' is as follows:-



NOTE: L=last_digit



n = (x-L)/10 #The same thing as n=x//10



a = 100 + 20L



d = 200



Our final answer is:-



=> (n/2) * (2a + (n-1)d ) + L^2



Substituting values for the variables,



=> [(x-L)/20] * [200 + 40L + [(x-L)/10]*200 - 200] + L^2



Taking the 20 in [(x-L)/20] and taking it to the RHS of * sign,



=> (x-L) * [10 + 2L + x - L -10] + L^2



=> (x-L)*(x+L) + L^2



=> x^2 - L^2 + L^2



=> x^2










share|improve this question
























  • Expand the terms and simplify. You'll end up with x^2. It's tedious but straightforward.
    – user2357112
    Nov 19 '18 at 18:32










  • It may help to express n as (x-last_digit)/10.
    – user2357112
    Nov 19 '18 at 18:33










  • Yes, I got x^2 in the end. @user2357112
    – Prabhat Soni
    Nov 21 '18 at 18:53










  • Is there some past mathematical theorem about this, or why this works or is this just a coincidence that this works?
    – Prabhat Soni
    Nov 21 '18 at 19:16










  • How big are the numbers you've tested this with? I think that for very big numbers (the only ones alternative squaring arrangements would help with), you should start to be worried about the imprecision of the floating point numbers introducing error. (Or just trying to store a too large number)
    – Patrick Haugh
    Nov 21 '18 at 19:36














0












0








0


1





I came up with this technique a few years ago. It seems to be working fine.



Input: a number



Output: Its' square



x=int(input("Enter the number whose square you wish to find out: "))  #decimal input invalid
last_digit=x%10
#We will use formula Sn= (n/2)*(2a+ (n-1)d) of AP
a=100 + last_digit*20 #100,20 are fixed values
d=200 #200 is a fixed value
n=(x-last_digit)/10

final_answer=(n/2)*(2*a + (n-1)*d) + last_digit**2 #These calculations are easier than x*x for a vvlarge x
#normal multiplication is d*d digits, but this is d*(d-1) or d*(d-2) digits

print("My answer: " ,format(final_answer,'f'))
print("Actual answer: ", x**2)


I have written comments to indicate what Im doing at each step



-> How does this work? Like seriously? I got this by observing some patterns and generalising them
-> This code was meant to work only for 3-digit numbers, but it works for all numbers. How?



By expanding/substitution, my 'derivation' is as follows:-



NOTE: L=last_digit



n = (x-L)/10 #The same thing as n=x//10



a = 100 + 20L



d = 200



Our final answer is:-



=> (n/2) * (2a + (n-1)d ) + L^2



Substituting values for the variables,



=> [(x-L)/20] * [200 + 40L + [(x-L)/10]*200 - 200] + L^2



Taking the 20 in [(x-L)/20] and taking it to the RHS of * sign,



=> (x-L) * [10 + 2L + x - L -10] + L^2



=> (x-L)*(x+L) + L^2



=> x^2 - L^2 + L^2



=> x^2










share|improve this question















I came up with this technique a few years ago. It seems to be working fine.



Input: a number



Output: Its' square



x=int(input("Enter the number whose square you wish to find out: "))  #decimal input invalid
last_digit=x%10
#We will use formula Sn= (n/2)*(2a+ (n-1)d) of AP
a=100 + last_digit*20 #100,20 are fixed values
d=200 #200 is a fixed value
n=(x-last_digit)/10

final_answer=(n/2)*(2*a + (n-1)*d) + last_digit**2 #These calculations are easier than x*x for a vvlarge x
#normal multiplication is d*d digits, but this is d*(d-1) or d*(d-2) digits

print("My answer: " ,format(final_answer,'f'))
print("Actual answer: ", x**2)


I have written comments to indicate what Im doing at each step



-> How does this work? Like seriously? I got this by observing some patterns and generalising them
-> This code was meant to work only for 3-digit numbers, but it works for all numbers. How?



By expanding/substitution, my 'derivation' is as follows:-



NOTE: L=last_digit



n = (x-L)/10 #The same thing as n=x//10



a = 100 + 20L



d = 200



Our final answer is:-



=> (n/2) * (2a + (n-1)d ) + L^2



Substituting values for the variables,



=> [(x-L)/20] * [200 + 40L + [(x-L)/10]*200 - 200] + L^2



Taking the 20 in [(x-L)/20] and taking it to the RHS of * sign,



=> (x-L) * [10 + 2L + x - L -10] + L^2



=> (x-L)*(x+L) + L^2



=> x^2 - L^2 + L^2



=> x^2







python python-3.x algorithm






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 11 '18 at 11:48









Mikkel

5,44821027




5,44821027










asked Nov 19 '18 at 18:21









Prabhat SoniPrabhat Soni

35




35












  • Expand the terms and simplify. You'll end up with x^2. It's tedious but straightforward.
    – user2357112
    Nov 19 '18 at 18:32










  • It may help to express n as (x-last_digit)/10.
    – user2357112
    Nov 19 '18 at 18:33










  • Yes, I got x^2 in the end. @user2357112
    – Prabhat Soni
    Nov 21 '18 at 18:53










  • Is there some past mathematical theorem about this, or why this works or is this just a coincidence that this works?
    – Prabhat Soni
    Nov 21 '18 at 19:16










  • How big are the numbers you've tested this with? I think that for very big numbers (the only ones alternative squaring arrangements would help with), you should start to be worried about the imprecision of the floating point numbers introducing error. (Or just trying to store a too large number)
    – Patrick Haugh
    Nov 21 '18 at 19:36


















  • Expand the terms and simplify. You'll end up with x^2. It's tedious but straightforward.
    – user2357112
    Nov 19 '18 at 18:32










  • It may help to express n as (x-last_digit)/10.
    – user2357112
    Nov 19 '18 at 18:33










  • Yes, I got x^2 in the end. @user2357112
    – Prabhat Soni
    Nov 21 '18 at 18:53










  • Is there some past mathematical theorem about this, or why this works or is this just a coincidence that this works?
    – Prabhat Soni
    Nov 21 '18 at 19:16










  • How big are the numbers you've tested this with? I think that for very big numbers (the only ones alternative squaring arrangements would help with), you should start to be worried about the imprecision of the floating point numbers introducing error. (Or just trying to store a too large number)
    – Patrick Haugh
    Nov 21 '18 at 19:36
















Expand the terms and simplify. You'll end up with x^2. It's tedious but straightforward.
– user2357112
Nov 19 '18 at 18:32




Expand the terms and simplify. You'll end up with x^2. It's tedious but straightforward.
– user2357112
Nov 19 '18 at 18:32












It may help to express n as (x-last_digit)/10.
– user2357112
Nov 19 '18 at 18:33




It may help to express n as (x-last_digit)/10.
– user2357112
Nov 19 '18 at 18:33












Yes, I got x^2 in the end. @user2357112
– Prabhat Soni
Nov 21 '18 at 18:53




Yes, I got x^2 in the end. @user2357112
– Prabhat Soni
Nov 21 '18 at 18:53












Is there some past mathematical theorem about this, or why this works or is this just a coincidence that this works?
– Prabhat Soni
Nov 21 '18 at 19:16




Is there some past mathematical theorem about this, or why this works or is this just a coincidence that this works?
– Prabhat Soni
Nov 21 '18 at 19:16












How big are the numbers you've tested this with? I think that for very big numbers (the only ones alternative squaring arrangements would help with), you should start to be worried about the imprecision of the floating point numbers introducing error. (Or just trying to store a too large number)
– Patrick Haugh
Nov 21 '18 at 19:36




How big are the numbers you've tested this with? I think that for very big numbers (the only ones alternative squaring arrangements would help with), you should start to be worried about the imprecision of the floating point numbers introducing error. (Or just trying to store a too large number)
– Patrick Haugh
Nov 21 '18 at 19:36












2 Answers
2






active

oldest

votes


















0














Your code is not giving correct output for 10 to 19 and
it's only give correct output when x//10 is multiple of 2 because of this expression (n/2)*(2*a + (n-1)*d) + last_digit**2 has n/2.
and for rest of test cases it is giving approximate answer.
and Expand the terms and You'll end up with x^2((2*last_digit/x) + 1) and now it's obvious why those magic numbers were giving correct output .






share|improve this answer





















  • 1) You said that you were getting x^2((2*last_digit/x) + 1) after expanding. However, I got something different. Read the update in the question for my proof. Please point out any mistakes 2) I donot see why n/2 is a problem 3) "it's only give correct output when x//10 is multiple of 2". Try inputting 10000000000000000000 , 2222222222222222222222 and observe output
    – Prabhat Soni
    Nov 21 '18 at 19:06












  • put n = x/10 you will get same answer as mine. and your computer don't calculates expression after minimizing it so n/2 does affect.
    – shubham jha
    Nov 22 '18 at 21:32










  • n=x/10 is incorrect both mathematically (Eg. 183 != 183/10) and in terms of programmng (183/10=18.3 and not 18 - it will be converted to a float value). Try putting input as 100000000000000000000. Here, n=x//10 = x/10 = (x-last_digit)/10. Here, also it is giving error in answer. The code is giving incorrect answer for all large numbers(odd and even)
    – Prabhat Soni
    Nov 23 '18 at 10:48



















0














Your algorithm is failing for large numbers. I tried it only for integers and here is the list of some integers where the result differed-




94906267
94906269
94906271
94906273
94906275
94906277
94906279
94906281
94906283
94906285
94906287
94906289
94906291
94906293
94906295
94906297
94906299
94906301
94906303
94906305
94906307
94906309
94906311
94906313
94906315
94906317
94906319
94906321
94906323
94906325
94906327
94906329
94906331
94906333
94906335
94906337
94906339
94906341
94906343
94906345
94906347
94906349
94906351
94906353
94906355
94906357
94906359
94906361
94906363
94906365
94906367
94906369
94906371
94906373
94906375
94906377
94906379
94906381
94906383
94906385
94906387
94906389
94906391
94906393
94906395
94906397
94906399
94906401
94906403
94906405
94906407
94906409
94906411
94906413
94906415
94906417
94906419
94906421
94906423
94906425
94906427
94906429
94906431
94906433
94906435
94906437
94906439
94906441
94906443
94906445
94906447
94906449
94906451
94906453
94906455
94906457
94906459
94906461
94906463
94906465
94906467
94906469
94906471
94906473
94906475
94906477
94906479
94906481
94906483
94906485
94906487
94906489
94906491
94906493
94906495
94906497
94906499
94906501
94906503
94906505
94906507
94906509
94906511
94906513
94906515
94906517
94906519
94906521
94906523
94906525
94906527
94906529
94906531
94906533
94906535
94906537
94906539
94906541
94906543
94906545
94906547
94906549
94906551
94906553
94906555
94906557
94906559
94906561
94906563
94906565
94906567
94906569
94906571
94906573
94906575
94906577
94906579
94906581
94906583
94906585
94906587
94906589
94906591
94906593
94906595
94906597
94906599
94906601
94906603
94906605
94906607
94906609
94906611
94906613
94906615
94906617
94906619
94906621
94906623
94906625
94906627
94906629
94906631
94906633
94906635
94906637
94906639
94906641
94906643
94906645
94906647
94906649
94906651
94906653
94906655
94906657
94906659
94906661
94906663
94906665
94906667
94906669
94906671
94906673
94906675
94906677
94906679
94906681
94906683
94906685
94906687
94906689
94906691
94906693
94906695
94906697
94906699
94906701
94906703
94906705
94906707
94906709
94906711
94906713
94906715
94906717
94906719
94906721
94906723
94906725
94906727
94906729
94906731
94906733
94906735
94906737
94906739
94906741
94906743
94906745
94906747
94906749
94906751
94906753
94906755
94906757
94906759
94906761
94906763
94906765
94906767
94906769
94906771
94906773
94906775
94906777
94906779
94906781
94906783
94906785
94906787
94906789
94906791
94906793
94906795
94906797
94906799
94906801
94906803
94906805
94906807
94906809
94906811
94906813
94906815
94906817
94906819
94906821
94906823
94906825
94906827
94906829
94906831
94906833
94906835
94906837
94906839
94906841
94906843
94906845
94906847
94906849
94906851
94906853
94906855
94906857
94906859
94906861
94906863
94906865
94906867
94906869
94906871
94906873
94906875
94906877
94906879
94906881
94906883
94906885
94906887
94906889
94906891
94906893
94906895
94906897
94906899
94906901
94906903
94906905
94906907
94906909
94906911
94906913
94906915
94906917
94906919
94906921
94906923
94906925
94906927
94906929
94906931
94906933
94906935
94906937
94906939
94906941
94906943
94906945
94906947
94906949
94906951
94906953
94906955
94906957
94906959
94906961
94906963
94906965
94906967
94906969
94906971
94906973
94906975
94906977
94906979
94906981
94906983
94906985
94906987
94906989
94906991
94906993
94906995
94906997
94906999
94907001
94907003
94907005
94907007
94907009
94907011
94907013
94907015
94907017
94907019
94907021
94907023
94907025
94907027
94907029
94907031
94907033
94907035
94907037
94907039
94907041
94907043
94907045
94907047
94907049
94907051
94907053
94907055
94907057
94907059
94907061
94907063
94907065
94907067
94907069
94907071
94907073
94907075
94907077
94907079
94907081
94907083
94907085
94907087
94907089
94907091
94907093
94907095
94907097
94907099
94907101
94907103
94907105
94907107
94907109
94907111
94907113
94907115
94907117
94907119
94907121
94907123
94907125
94907127
94907129
94907131
94907133
94907135
94907137
94907139
94907141
94907143
94907145
94907147
94907149
94907151
94907153
94907155
94907157
94907159
94907161
94907163
94907165
94907167
94907169
94907171
94907173
94907175
94907177
94907179
94907181
94907183
94907185
94907187
94907189
94907191
94907193
94907195
94907197
94907199
94907201
94907203
94907205
94907207
94907209
94907211
94907213
94907215
94907217
94907219
94907221
94907223
94907225
94907227
94907229
94907231
94907233
94907235
94907237
94907239
94907241
94907243
94907245
94907247
94907249
94907251
94907253
94907255
94907257
94907259
94907261
94907263
94907265
94907267
94907269
94907271
94907273
94907275
94907277
94907279
94907281
94907283
94907285
94907287
94907289
94907291
94907293
94907295
94907297
94907299
94907301
94907303
94907305
94907307
94907309
94907311
94907313
94907315
94907317
94907319
94907321
94907323
94907325
94907327
94907329
94907331
94907333
94907335
94907337
94907339
94907341
94907343
94907345
94907347
94907349
94907351
94907353
94907355
94907357
94907359
94907361
94907363
94907365
94907367
94907369
94907371
94907373
94907375
94907377
94907379
94907381
94907383
94907385
94907387
94907389
94907391
94907393
94907395
94907397
94907399
94907401
94907403
94907405
94907407
94907409
94907411
94907413
94907415
94907417
94907419
94907421
94907423
94907425
94907427
94907429
94907431
94907433
94907435
94907437
94907439
94907441
94907443
94907445
94907447
94907449
94907451
94907453
94907455
94907457
94907459
94907461
94907463
94907465
94907467
94907469
94907471
94907473
94907475
94907477
94907479
94907481
94907483
94907485
94907487
94907489
94907491
94907493
94907495
94907497
94907499
94907501
94907503
94907505
94907507
94907509
94907511
94907513
94907515
94907517
94907519
94907521
94907523
94907525
94907527
94907529
94907531
94907533
94907535
94907537
94907539
94907541
94907543
94907545
94907547
94907549
94907551
94907553
94907555
94907557
94907559
94907561
94907563
94907565
94907567
94907569
94907571
94907573
94907575
94907577
94907579
94907581
94907583
94907585
94907587
94907589
94907591
94907593
94907595
94907597
94907599
94907601
94907603
94907605
94907607




And so on...



An interesting thing to note here is all the numbers which are creating the problem are odd.






share|improve this answer























  • Can you give some more context to your answer? What "list" are you taking about?
    – 16num
    Nov 22 '18 at 17:05










  • By 'list', Archit means 'examples of values' and not list as in array. Archit, the code is giving incorrect answer for even values as well - try giving inputs with 4-5 more digits
    – Prabhat Soni
    Nov 23 '18 at 10:50











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53380537%2falternate-way-of-squaring-a-number%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Your code is not giving correct output for 10 to 19 and
it's only give correct output when x//10 is multiple of 2 because of this expression (n/2)*(2*a + (n-1)*d) + last_digit**2 has n/2.
and for rest of test cases it is giving approximate answer.
and Expand the terms and You'll end up with x^2((2*last_digit/x) + 1) and now it's obvious why those magic numbers were giving correct output .






share|improve this answer





















  • 1) You said that you were getting x^2((2*last_digit/x) + 1) after expanding. However, I got something different. Read the update in the question for my proof. Please point out any mistakes 2) I donot see why n/2 is a problem 3) "it's only give correct output when x//10 is multiple of 2". Try inputting 10000000000000000000 , 2222222222222222222222 and observe output
    – Prabhat Soni
    Nov 21 '18 at 19:06












  • put n = x/10 you will get same answer as mine. and your computer don't calculates expression after minimizing it so n/2 does affect.
    – shubham jha
    Nov 22 '18 at 21:32










  • n=x/10 is incorrect both mathematically (Eg. 183 != 183/10) and in terms of programmng (183/10=18.3 and not 18 - it will be converted to a float value). Try putting input as 100000000000000000000. Here, n=x//10 = x/10 = (x-last_digit)/10. Here, also it is giving error in answer. The code is giving incorrect answer for all large numbers(odd and even)
    – Prabhat Soni
    Nov 23 '18 at 10:48
















0














Your code is not giving correct output for 10 to 19 and
it's only give correct output when x//10 is multiple of 2 because of this expression (n/2)*(2*a + (n-1)*d) + last_digit**2 has n/2.
and for rest of test cases it is giving approximate answer.
and Expand the terms and You'll end up with x^2((2*last_digit/x) + 1) and now it's obvious why those magic numbers were giving correct output .






share|improve this answer





















  • 1) You said that you were getting x^2((2*last_digit/x) + 1) after expanding. However, I got something different. Read the update in the question for my proof. Please point out any mistakes 2) I donot see why n/2 is a problem 3) "it's only give correct output when x//10 is multiple of 2". Try inputting 10000000000000000000 , 2222222222222222222222 and observe output
    – Prabhat Soni
    Nov 21 '18 at 19:06












  • put n = x/10 you will get same answer as mine. and your computer don't calculates expression after minimizing it so n/2 does affect.
    – shubham jha
    Nov 22 '18 at 21:32










  • n=x/10 is incorrect both mathematically (Eg. 183 != 183/10) and in terms of programmng (183/10=18.3 and not 18 - it will be converted to a float value). Try putting input as 100000000000000000000. Here, n=x//10 = x/10 = (x-last_digit)/10. Here, also it is giving error in answer. The code is giving incorrect answer for all large numbers(odd and even)
    – Prabhat Soni
    Nov 23 '18 at 10:48














0












0








0






Your code is not giving correct output for 10 to 19 and
it's only give correct output when x//10 is multiple of 2 because of this expression (n/2)*(2*a + (n-1)*d) + last_digit**2 has n/2.
and for rest of test cases it is giving approximate answer.
and Expand the terms and You'll end up with x^2((2*last_digit/x) + 1) and now it's obvious why those magic numbers were giving correct output .






share|improve this answer












Your code is not giving correct output for 10 to 19 and
it's only give correct output when x//10 is multiple of 2 because of this expression (n/2)*(2*a + (n-1)*d) + last_digit**2 has n/2.
and for rest of test cases it is giving approximate answer.
and Expand the terms and You'll end up with x^2((2*last_digit/x) + 1) and now it's obvious why those magic numbers were giving correct output .







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 '18 at 22:46









shubham jhashubham jha

11




11












  • 1) You said that you were getting x^2((2*last_digit/x) + 1) after expanding. However, I got something different. Read the update in the question for my proof. Please point out any mistakes 2) I donot see why n/2 is a problem 3) "it's only give correct output when x//10 is multiple of 2". Try inputting 10000000000000000000 , 2222222222222222222222 and observe output
    – Prabhat Soni
    Nov 21 '18 at 19:06












  • put n = x/10 you will get same answer as mine. and your computer don't calculates expression after minimizing it so n/2 does affect.
    – shubham jha
    Nov 22 '18 at 21:32










  • n=x/10 is incorrect both mathematically (Eg. 183 != 183/10) and in terms of programmng (183/10=18.3 and not 18 - it will be converted to a float value). Try putting input as 100000000000000000000. Here, n=x//10 = x/10 = (x-last_digit)/10. Here, also it is giving error in answer. The code is giving incorrect answer for all large numbers(odd and even)
    – Prabhat Soni
    Nov 23 '18 at 10:48


















  • 1) You said that you were getting x^2((2*last_digit/x) + 1) after expanding. However, I got something different. Read the update in the question for my proof. Please point out any mistakes 2) I donot see why n/2 is a problem 3) "it's only give correct output when x//10 is multiple of 2". Try inputting 10000000000000000000 , 2222222222222222222222 and observe output
    – Prabhat Soni
    Nov 21 '18 at 19:06












  • put n = x/10 you will get same answer as mine. and your computer don't calculates expression after minimizing it so n/2 does affect.
    – shubham jha
    Nov 22 '18 at 21:32










  • n=x/10 is incorrect both mathematically (Eg. 183 != 183/10) and in terms of programmng (183/10=18.3 and not 18 - it will be converted to a float value). Try putting input as 100000000000000000000. Here, n=x//10 = x/10 = (x-last_digit)/10. Here, also it is giving error in answer. The code is giving incorrect answer for all large numbers(odd and even)
    – Prabhat Soni
    Nov 23 '18 at 10:48
















1) You said that you were getting x^2((2*last_digit/x) + 1) after expanding. However, I got something different. Read the update in the question for my proof. Please point out any mistakes 2) I donot see why n/2 is a problem 3) "it's only give correct output when x//10 is multiple of 2". Try inputting 10000000000000000000 , 2222222222222222222222 and observe output
– Prabhat Soni
Nov 21 '18 at 19:06






1) You said that you were getting x^2((2*last_digit/x) + 1) after expanding. However, I got something different. Read the update in the question for my proof. Please point out any mistakes 2) I donot see why n/2 is a problem 3) "it's only give correct output when x//10 is multiple of 2". Try inputting 10000000000000000000 , 2222222222222222222222 and observe output
– Prabhat Soni
Nov 21 '18 at 19:06














put n = x/10 you will get same answer as mine. and your computer don't calculates expression after minimizing it so n/2 does affect.
– shubham jha
Nov 22 '18 at 21:32




put n = x/10 you will get same answer as mine. and your computer don't calculates expression after minimizing it so n/2 does affect.
– shubham jha
Nov 22 '18 at 21:32












n=x/10 is incorrect both mathematically (Eg. 183 != 183/10) and in terms of programmng (183/10=18.3 and not 18 - it will be converted to a float value). Try putting input as 100000000000000000000. Here, n=x//10 = x/10 = (x-last_digit)/10. Here, also it is giving error in answer. The code is giving incorrect answer for all large numbers(odd and even)
– Prabhat Soni
Nov 23 '18 at 10:48




n=x/10 is incorrect both mathematically (Eg. 183 != 183/10) and in terms of programmng (183/10=18.3 and not 18 - it will be converted to a float value). Try putting input as 100000000000000000000. Here, n=x//10 = x/10 = (x-last_digit)/10. Here, also it is giving error in answer. The code is giving incorrect answer for all large numbers(odd and even)
– Prabhat Soni
Nov 23 '18 at 10:48













0














Your algorithm is failing for large numbers. I tried it only for integers and here is the list of some integers where the result differed-




94906267
94906269
94906271
94906273
94906275
94906277
94906279
94906281
94906283
94906285
94906287
94906289
94906291
94906293
94906295
94906297
94906299
94906301
94906303
94906305
94906307
94906309
94906311
94906313
94906315
94906317
94906319
94906321
94906323
94906325
94906327
94906329
94906331
94906333
94906335
94906337
94906339
94906341
94906343
94906345
94906347
94906349
94906351
94906353
94906355
94906357
94906359
94906361
94906363
94906365
94906367
94906369
94906371
94906373
94906375
94906377
94906379
94906381
94906383
94906385
94906387
94906389
94906391
94906393
94906395
94906397
94906399
94906401
94906403
94906405
94906407
94906409
94906411
94906413
94906415
94906417
94906419
94906421
94906423
94906425
94906427
94906429
94906431
94906433
94906435
94906437
94906439
94906441
94906443
94906445
94906447
94906449
94906451
94906453
94906455
94906457
94906459
94906461
94906463
94906465
94906467
94906469
94906471
94906473
94906475
94906477
94906479
94906481
94906483
94906485
94906487
94906489
94906491
94906493
94906495
94906497
94906499
94906501
94906503
94906505
94906507
94906509
94906511
94906513
94906515
94906517
94906519
94906521
94906523
94906525
94906527
94906529
94906531
94906533
94906535
94906537
94906539
94906541
94906543
94906545
94906547
94906549
94906551
94906553
94906555
94906557
94906559
94906561
94906563
94906565
94906567
94906569
94906571
94906573
94906575
94906577
94906579
94906581
94906583
94906585
94906587
94906589
94906591
94906593
94906595
94906597
94906599
94906601
94906603
94906605
94906607
94906609
94906611
94906613
94906615
94906617
94906619
94906621
94906623
94906625
94906627
94906629
94906631
94906633
94906635
94906637
94906639
94906641
94906643
94906645
94906647
94906649
94906651
94906653
94906655
94906657
94906659
94906661
94906663
94906665
94906667
94906669
94906671
94906673
94906675
94906677
94906679
94906681
94906683
94906685
94906687
94906689
94906691
94906693
94906695
94906697
94906699
94906701
94906703
94906705
94906707
94906709
94906711
94906713
94906715
94906717
94906719
94906721
94906723
94906725
94906727
94906729
94906731
94906733
94906735
94906737
94906739
94906741
94906743
94906745
94906747
94906749
94906751
94906753
94906755
94906757
94906759
94906761
94906763
94906765
94906767
94906769
94906771
94906773
94906775
94906777
94906779
94906781
94906783
94906785
94906787
94906789
94906791
94906793
94906795
94906797
94906799
94906801
94906803
94906805
94906807
94906809
94906811
94906813
94906815
94906817
94906819
94906821
94906823
94906825
94906827
94906829
94906831
94906833
94906835
94906837
94906839
94906841
94906843
94906845
94906847
94906849
94906851
94906853
94906855
94906857
94906859
94906861
94906863
94906865
94906867
94906869
94906871
94906873
94906875
94906877
94906879
94906881
94906883
94906885
94906887
94906889
94906891
94906893
94906895
94906897
94906899
94906901
94906903
94906905
94906907
94906909
94906911
94906913
94906915
94906917
94906919
94906921
94906923
94906925
94906927
94906929
94906931
94906933
94906935
94906937
94906939
94906941
94906943
94906945
94906947
94906949
94906951
94906953
94906955
94906957
94906959
94906961
94906963
94906965
94906967
94906969
94906971
94906973
94906975
94906977
94906979
94906981
94906983
94906985
94906987
94906989
94906991
94906993
94906995
94906997
94906999
94907001
94907003
94907005
94907007
94907009
94907011
94907013
94907015
94907017
94907019
94907021
94907023
94907025
94907027
94907029
94907031
94907033
94907035
94907037
94907039
94907041
94907043
94907045
94907047
94907049
94907051
94907053
94907055
94907057
94907059
94907061
94907063
94907065
94907067
94907069
94907071
94907073
94907075
94907077
94907079
94907081
94907083
94907085
94907087
94907089
94907091
94907093
94907095
94907097
94907099
94907101
94907103
94907105
94907107
94907109
94907111
94907113
94907115
94907117
94907119
94907121
94907123
94907125
94907127
94907129
94907131
94907133
94907135
94907137
94907139
94907141
94907143
94907145
94907147
94907149
94907151
94907153
94907155
94907157
94907159
94907161
94907163
94907165
94907167
94907169
94907171
94907173
94907175
94907177
94907179
94907181
94907183
94907185
94907187
94907189
94907191
94907193
94907195
94907197
94907199
94907201
94907203
94907205
94907207
94907209
94907211
94907213
94907215
94907217
94907219
94907221
94907223
94907225
94907227
94907229
94907231
94907233
94907235
94907237
94907239
94907241
94907243
94907245
94907247
94907249
94907251
94907253
94907255
94907257
94907259
94907261
94907263
94907265
94907267
94907269
94907271
94907273
94907275
94907277
94907279
94907281
94907283
94907285
94907287
94907289
94907291
94907293
94907295
94907297
94907299
94907301
94907303
94907305
94907307
94907309
94907311
94907313
94907315
94907317
94907319
94907321
94907323
94907325
94907327
94907329
94907331
94907333
94907335
94907337
94907339
94907341
94907343
94907345
94907347
94907349
94907351
94907353
94907355
94907357
94907359
94907361
94907363
94907365
94907367
94907369
94907371
94907373
94907375
94907377
94907379
94907381
94907383
94907385
94907387
94907389
94907391
94907393
94907395
94907397
94907399
94907401
94907403
94907405
94907407
94907409
94907411
94907413
94907415
94907417
94907419
94907421
94907423
94907425
94907427
94907429
94907431
94907433
94907435
94907437
94907439
94907441
94907443
94907445
94907447
94907449
94907451
94907453
94907455
94907457
94907459
94907461
94907463
94907465
94907467
94907469
94907471
94907473
94907475
94907477
94907479
94907481
94907483
94907485
94907487
94907489
94907491
94907493
94907495
94907497
94907499
94907501
94907503
94907505
94907507
94907509
94907511
94907513
94907515
94907517
94907519
94907521
94907523
94907525
94907527
94907529
94907531
94907533
94907535
94907537
94907539
94907541
94907543
94907545
94907547
94907549
94907551
94907553
94907555
94907557
94907559
94907561
94907563
94907565
94907567
94907569
94907571
94907573
94907575
94907577
94907579
94907581
94907583
94907585
94907587
94907589
94907591
94907593
94907595
94907597
94907599
94907601
94907603
94907605
94907607




And so on...



An interesting thing to note here is all the numbers which are creating the problem are odd.






share|improve this answer























  • Can you give some more context to your answer? What "list" are you taking about?
    – 16num
    Nov 22 '18 at 17:05










  • By 'list', Archit means 'examples of values' and not list as in array. Archit, the code is giving incorrect answer for even values as well - try giving inputs with 4-5 more digits
    – Prabhat Soni
    Nov 23 '18 at 10:50
















0














Your algorithm is failing for large numbers. I tried it only for integers and here is the list of some integers where the result differed-




94906267
94906269
94906271
94906273
94906275
94906277
94906279
94906281
94906283
94906285
94906287
94906289
94906291
94906293
94906295
94906297
94906299
94906301
94906303
94906305
94906307
94906309
94906311
94906313
94906315
94906317
94906319
94906321
94906323
94906325
94906327
94906329
94906331
94906333
94906335
94906337
94906339
94906341
94906343
94906345
94906347
94906349
94906351
94906353
94906355
94906357
94906359
94906361
94906363
94906365
94906367
94906369
94906371
94906373
94906375
94906377
94906379
94906381
94906383
94906385
94906387
94906389
94906391
94906393
94906395
94906397
94906399
94906401
94906403
94906405
94906407
94906409
94906411
94906413
94906415
94906417
94906419
94906421
94906423
94906425
94906427
94906429
94906431
94906433
94906435
94906437
94906439
94906441
94906443
94906445
94906447
94906449
94906451
94906453
94906455
94906457
94906459
94906461
94906463
94906465
94906467
94906469
94906471
94906473
94906475
94906477
94906479
94906481
94906483
94906485
94906487
94906489
94906491
94906493
94906495
94906497
94906499
94906501
94906503
94906505
94906507
94906509
94906511
94906513
94906515
94906517
94906519
94906521
94906523
94906525
94906527
94906529
94906531
94906533
94906535
94906537
94906539
94906541
94906543
94906545
94906547
94906549
94906551
94906553
94906555
94906557
94906559
94906561
94906563
94906565
94906567
94906569
94906571
94906573
94906575
94906577
94906579
94906581
94906583
94906585
94906587
94906589
94906591
94906593
94906595
94906597
94906599
94906601
94906603
94906605
94906607
94906609
94906611
94906613
94906615
94906617
94906619
94906621
94906623
94906625
94906627
94906629
94906631
94906633
94906635
94906637
94906639
94906641
94906643
94906645
94906647
94906649
94906651
94906653
94906655
94906657
94906659
94906661
94906663
94906665
94906667
94906669
94906671
94906673
94906675
94906677
94906679
94906681
94906683
94906685
94906687
94906689
94906691
94906693
94906695
94906697
94906699
94906701
94906703
94906705
94906707
94906709
94906711
94906713
94906715
94906717
94906719
94906721
94906723
94906725
94906727
94906729
94906731
94906733
94906735
94906737
94906739
94906741
94906743
94906745
94906747
94906749
94906751
94906753
94906755
94906757
94906759
94906761
94906763
94906765
94906767
94906769
94906771
94906773
94906775
94906777
94906779
94906781
94906783
94906785
94906787
94906789
94906791
94906793
94906795
94906797
94906799
94906801
94906803
94906805
94906807
94906809
94906811
94906813
94906815
94906817
94906819
94906821
94906823
94906825
94906827
94906829
94906831
94906833
94906835
94906837
94906839
94906841
94906843
94906845
94906847
94906849
94906851
94906853
94906855
94906857
94906859
94906861
94906863
94906865
94906867
94906869
94906871
94906873
94906875
94906877
94906879
94906881
94906883
94906885
94906887
94906889
94906891
94906893
94906895
94906897
94906899
94906901
94906903
94906905
94906907
94906909
94906911
94906913
94906915
94906917
94906919
94906921
94906923
94906925
94906927
94906929
94906931
94906933
94906935
94906937
94906939
94906941
94906943
94906945
94906947
94906949
94906951
94906953
94906955
94906957
94906959
94906961
94906963
94906965
94906967
94906969
94906971
94906973
94906975
94906977
94906979
94906981
94906983
94906985
94906987
94906989
94906991
94906993
94906995
94906997
94906999
94907001
94907003
94907005
94907007
94907009
94907011
94907013
94907015
94907017
94907019
94907021
94907023
94907025
94907027
94907029
94907031
94907033
94907035
94907037
94907039
94907041
94907043
94907045
94907047
94907049
94907051
94907053
94907055
94907057
94907059
94907061
94907063
94907065
94907067
94907069
94907071
94907073
94907075
94907077
94907079
94907081
94907083
94907085
94907087
94907089
94907091
94907093
94907095
94907097
94907099
94907101
94907103
94907105
94907107
94907109
94907111
94907113
94907115
94907117
94907119
94907121
94907123
94907125
94907127
94907129
94907131
94907133
94907135
94907137
94907139
94907141
94907143
94907145
94907147
94907149
94907151
94907153
94907155
94907157
94907159
94907161
94907163
94907165
94907167
94907169
94907171
94907173
94907175
94907177
94907179
94907181
94907183
94907185
94907187
94907189
94907191
94907193
94907195
94907197
94907199
94907201
94907203
94907205
94907207
94907209
94907211
94907213
94907215
94907217
94907219
94907221
94907223
94907225
94907227
94907229
94907231
94907233
94907235
94907237
94907239
94907241
94907243
94907245
94907247
94907249
94907251
94907253
94907255
94907257
94907259
94907261
94907263
94907265
94907267
94907269
94907271
94907273
94907275
94907277
94907279
94907281
94907283
94907285
94907287
94907289
94907291
94907293
94907295
94907297
94907299
94907301
94907303
94907305
94907307
94907309
94907311
94907313
94907315
94907317
94907319
94907321
94907323
94907325
94907327
94907329
94907331
94907333
94907335
94907337
94907339
94907341
94907343
94907345
94907347
94907349
94907351
94907353
94907355
94907357
94907359
94907361
94907363
94907365
94907367
94907369
94907371
94907373
94907375
94907377
94907379
94907381
94907383
94907385
94907387
94907389
94907391
94907393
94907395
94907397
94907399
94907401
94907403
94907405
94907407
94907409
94907411
94907413
94907415
94907417
94907419
94907421
94907423
94907425
94907427
94907429
94907431
94907433
94907435
94907437
94907439
94907441
94907443
94907445
94907447
94907449
94907451
94907453
94907455
94907457
94907459
94907461
94907463
94907465
94907467
94907469
94907471
94907473
94907475
94907477
94907479
94907481
94907483
94907485
94907487
94907489
94907491
94907493
94907495
94907497
94907499
94907501
94907503
94907505
94907507
94907509
94907511
94907513
94907515
94907517
94907519
94907521
94907523
94907525
94907527
94907529
94907531
94907533
94907535
94907537
94907539
94907541
94907543
94907545
94907547
94907549
94907551
94907553
94907555
94907557
94907559
94907561
94907563
94907565
94907567
94907569
94907571
94907573
94907575
94907577
94907579
94907581
94907583
94907585
94907587
94907589
94907591
94907593
94907595
94907597
94907599
94907601
94907603
94907605
94907607




And so on...



An interesting thing to note here is all the numbers which are creating the problem are odd.






share|improve this answer























  • Can you give some more context to your answer? What "list" are you taking about?
    – 16num
    Nov 22 '18 at 17:05










  • By 'list', Archit means 'examples of values' and not list as in array. Archit, the code is giving incorrect answer for even values as well - try giving inputs with 4-5 more digits
    – Prabhat Soni
    Nov 23 '18 at 10:50














0












0








0






Your algorithm is failing for large numbers. I tried it only for integers and here is the list of some integers where the result differed-




94906267
94906269
94906271
94906273
94906275
94906277
94906279
94906281
94906283
94906285
94906287
94906289
94906291
94906293
94906295
94906297
94906299
94906301
94906303
94906305
94906307
94906309
94906311
94906313
94906315
94906317
94906319
94906321
94906323
94906325
94906327
94906329
94906331
94906333
94906335
94906337
94906339
94906341
94906343
94906345
94906347
94906349
94906351
94906353
94906355
94906357
94906359
94906361
94906363
94906365
94906367
94906369
94906371
94906373
94906375
94906377
94906379
94906381
94906383
94906385
94906387
94906389
94906391
94906393
94906395
94906397
94906399
94906401
94906403
94906405
94906407
94906409
94906411
94906413
94906415
94906417
94906419
94906421
94906423
94906425
94906427
94906429
94906431
94906433
94906435
94906437
94906439
94906441
94906443
94906445
94906447
94906449
94906451
94906453
94906455
94906457
94906459
94906461
94906463
94906465
94906467
94906469
94906471
94906473
94906475
94906477
94906479
94906481
94906483
94906485
94906487
94906489
94906491
94906493
94906495
94906497
94906499
94906501
94906503
94906505
94906507
94906509
94906511
94906513
94906515
94906517
94906519
94906521
94906523
94906525
94906527
94906529
94906531
94906533
94906535
94906537
94906539
94906541
94906543
94906545
94906547
94906549
94906551
94906553
94906555
94906557
94906559
94906561
94906563
94906565
94906567
94906569
94906571
94906573
94906575
94906577
94906579
94906581
94906583
94906585
94906587
94906589
94906591
94906593
94906595
94906597
94906599
94906601
94906603
94906605
94906607
94906609
94906611
94906613
94906615
94906617
94906619
94906621
94906623
94906625
94906627
94906629
94906631
94906633
94906635
94906637
94906639
94906641
94906643
94906645
94906647
94906649
94906651
94906653
94906655
94906657
94906659
94906661
94906663
94906665
94906667
94906669
94906671
94906673
94906675
94906677
94906679
94906681
94906683
94906685
94906687
94906689
94906691
94906693
94906695
94906697
94906699
94906701
94906703
94906705
94906707
94906709
94906711
94906713
94906715
94906717
94906719
94906721
94906723
94906725
94906727
94906729
94906731
94906733
94906735
94906737
94906739
94906741
94906743
94906745
94906747
94906749
94906751
94906753
94906755
94906757
94906759
94906761
94906763
94906765
94906767
94906769
94906771
94906773
94906775
94906777
94906779
94906781
94906783
94906785
94906787
94906789
94906791
94906793
94906795
94906797
94906799
94906801
94906803
94906805
94906807
94906809
94906811
94906813
94906815
94906817
94906819
94906821
94906823
94906825
94906827
94906829
94906831
94906833
94906835
94906837
94906839
94906841
94906843
94906845
94906847
94906849
94906851
94906853
94906855
94906857
94906859
94906861
94906863
94906865
94906867
94906869
94906871
94906873
94906875
94906877
94906879
94906881
94906883
94906885
94906887
94906889
94906891
94906893
94906895
94906897
94906899
94906901
94906903
94906905
94906907
94906909
94906911
94906913
94906915
94906917
94906919
94906921
94906923
94906925
94906927
94906929
94906931
94906933
94906935
94906937
94906939
94906941
94906943
94906945
94906947
94906949
94906951
94906953
94906955
94906957
94906959
94906961
94906963
94906965
94906967
94906969
94906971
94906973
94906975
94906977
94906979
94906981
94906983
94906985
94906987
94906989
94906991
94906993
94906995
94906997
94906999
94907001
94907003
94907005
94907007
94907009
94907011
94907013
94907015
94907017
94907019
94907021
94907023
94907025
94907027
94907029
94907031
94907033
94907035
94907037
94907039
94907041
94907043
94907045
94907047
94907049
94907051
94907053
94907055
94907057
94907059
94907061
94907063
94907065
94907067
94907069
94907071
94907073
94907075
94907077
94907079
94907081
94907083
94907085
94907087
94907089
94907091
94907093
94907095
94907097
94907099
94907101
94907103
94907105
94907107
94907109
94907111
94907113
94907115
94907117
94907119
94907121
94907123
94907125
94907127
94907129
94907131
94907133
94907135
94907137
94907139
94907141
94907143
94907145
94907147
94907149
94907151
94907153
94907155
94907157
94907159
94907161
94907163
94907165
94907167
94907169
94907171
94907173
94907175
94907177
94907179
94907181
94907183
94907185
94907187
94907189
94907191
94907193
94907195
94907197
94907199
94907201
94907203
94907205
94907207
94907209
94907211
94907213
94907215
94907217
94907219
94907221
94907223
94907225
94907227
94907229
94907231
94907233
94907235
94907237
94907239
94907241
94907243
94907245
94907247
94907249
94907251
94907253
94907255
94907257
94907259
94907261
94907263
94907265
94907267
94907269
94907271
94907273
94907275
94907277
94907279
94907281
94907283
94907285
94907287
94907289
94907291
94907293
94907295
94907297
94907299
94907301
94907303
94907305
94907307
94907309
94907311
94907313
94907315
94907317
94907319
94907321
94907323
94907325
94907327
94907329
94907331
94907333
94907335
94907337
94907339
94907341
94907343
94907345
94907347
94907349
94907351
94907353
94907355
94907357
94907359
94907361
94907363
94907365
94907367
94907369
94907371
94907373
94907375
94907377
94907379
94907381
94907383
94907385
94907387
94907389
94907391
94907393
94907395
94907397
94907399
94907401
94907403
94907405
94907407
94907409
94907411
94907413
94907415
94907417
94907419
94907421
94907423
94907425
94907427
94907429
94907431
94907433
94907435
94907437
94907439
94907441
94907443
94907445
94907447
94907449
94907451
94907453
94907455
94907457
94907459
94907461
94907463
94907465
94907467
94907469
94907471
94907473
94907475
94907477
94907479
94907481
94907483
94907485
94907487
94907489
94907491
94907493
94907495
94907497
94907499
94907501
94907503
94907505
94907507
94907509
94907511
94907513
94907515
94907517
94907519
94907521
94907523
94907525
94907527
94907529
94907531
94907533
94907535
94907537
94907539
94907541
94907543
94907545
94907547
94907549
94907551
94907553
94907555
94907557
94907559
94907561
94907563
94907565
94907567
94907569
94907571
94907573
94907575
94907577
94907579
94907581
94907583
94907585
94907587
94907589
94907591
94907593
94907595
94907597
94907599
94907601
94907603
94907605
94907607




And so on...



An interesting thing to note here is all the numbers which are creating the problem are odd.






share|improve this answer














Your algorithm is failing for large numbers. I tried it only for integers and here is the list of some integers where the result differed-




94906267
94906269
94906271
94906273
94906275
94906277
94906279
94906281
94906283
94906285
94906287
94906289
94906291
94906293
94906295
94906297
94906299
94906301
94906303
94906305
94906307
94906309
94906311
94906313
94906315
94906317
94906319
94906321
94906323
94906325
94906327
94906329
94906331
94906333
94906335
94906337
94906339
94906341
94906343
94906345
94906347
94906349
94906351
94906353
94906355
94906357
94906359
94906361
94906363
94906365
94906367
94906369
94906371
94906373
94906375
94906377
94906379
94906381
94906383
94906385
94906387
94906389
94906391
94906393
94906395
94906397
94906399
94906401
94906403
94906405
94906407
94906409
94906411
94906413
94906415
94906417
94906419
94906421
94906423
94906425
94906427
94906429
94906431
94906433
94906435
94906437
94906439
94906441
94906443
94906445
94906447
94906449
94906451
94906453
94906455
94906457
94906459
94906461
94906463
94906465
94906467
94906469
94906471
94906473
94906475
94906477
94906479
94906481
94906483
94906485
94906487
94906489
94906491
94906493
94906495
94906497
94906499
94906501
94906503
94906505
94906507
94906509
94906511
94906513
94906515
94906517
94906519
94906521
94906523
94906525
94906527
94906529
94906531
94906533
94906535
94906537
94906539
94906541
94906543
94906545
94906547
94906549
94906551
94906553
94906555
94906557
94906559
94906561
94906563
94906565
94906567
94906569
94906571
94906573
94906575
94906577
94906579
94906581
94906583
94906585
94906587
94906589
94906591
94906593
94906595
94906597
94906599
94906601
94906603
94906605
94906607
94906609
94906611
94906613
94906615
94906617
94906619
94906621
94906623
94906625
94906627
94906629
94906631
94906633
94906635
94906637
94906639
94906641
94906643
94906645
94906647
94906649
94906651
94906653
94906655
94906657
94906659
94906661
94906663
94906665
94906667
94906669
94906671
94906673
94906675
94906677
94906679
94906681
94906683
94906685
94906687
94906689
94906691
94906693
94906695
94906697
94906699
94906701
94906703
94906705
94906707
94906709
94906711
94906713
94906715
94906717
94906719
94906721
94906723
94906725
94906727
94906729
94906731
94906733
94906735
94906737
94906739
94906741
94906743
94906745
94906747
94906749
94906751
94906753
94906755
94906757
94906759
94906761
94906763
94906765
94906767
94906769
94906771
94906773
94906775
94906777
94906779
94906781
94906783
94906785
94906787
94906789
94906791
94906793
94906795
94906797
94906799
94906801
94906803
94906805
94906807
94906809
94906811
94906813
94906815
94906817
94906819
94906821
94906823
94906825
94906827
94906829
94906831
94906833
94906835
94906837
94906839
94906841
94906843
94906845
94906847
94906849
94906851
94906853
94906855
94906857
94906859
94906861
94906863
94906865
94906867
94906869
94906871
94906873
94906875
94906877
94906879
94906881
94906883
94906885
94906887
94906889
94906891
94906893
94906895
94906897
94906899
94906901
94906903
94906905
94906907
94906909
94906911
94906913
94906915
94906917
94906919
94906921
94906923
94906925
94906927
94906929
94906931
94906933
94906935
94906937
94906939
94906941
94906943
94906945
94906947
94906949
94906951
94906953
94906955
94906957
94906959
94906961
94906963
94906965
94906967
94906969
94906971
94906973
94906975
94906977
94906979
94906981
94906983
94906985
94906987
94906989
94906991
94906993
94906995
94906997
94906999
94907001
94907003
94907005
94907007
94907009
94907011
94907013
94907015
94907017
94907019
94907021
94907023
94907025
94907027
94907029
94907031
94907033
94907035
94907037
94907039
94907041
94907043
94907045
94907047
94907049
94907051
94907053
94907055
94907057
94907059
94907061
94907063
94907065
94907067
94907069
94907071
94907073
94907075
94907077
94907079
94907081
94907083
94907085
94907087
94907089
94907091
94907093
94907095
94907097
94907099
94907101
94907103
94907105
94907107
94907109
94907111
94907113
94907115
94907117
94907119
94907121
94907123
94907125
94907127
94907129
94907131
94907133
94907135
94907137
94907139
94907141
94907143
94907145
94907147
94907149
94907151
94907153
94907155
94907157
94907159
94907161
94907163
94907165
94907167
94907169
94907171
94907173
94907175
94907177
94907179
94907181
94907183
94907185
94907187
94907189
94907191
94907193
94907195
94907197
94907199
94907201
94907203
94907205
94907207
94907209
94907211
94907213
94907215
94907217
94907219
94907221
94907223
94907225
94907227
94907229
94907231
94907233
94907235
94907237
94907239
94907241
94907243
94907245
94907247
94907249
94907251
94907253
94907255
94907257
94907259
94907261
94907263
94907265
94907267
94907269
94907271
94907273
94907275
94907277
94907279
94907281
94907283
94907285
94907287
94907289
94907291
94907293
94907295
94907297
94907299
94907301
94907303
94907305
94907307
94907309
94907311
94907313
94907315
94907317
94907319
94907321
94907323
94907325
94907327
94907329
94907331
94907333
94907335
94907337
94907339
94907341
94907343
94907345
94907347
94907349
94907351
94907353
94907355
94907357
94907359
94907361
94907363
94907365
94907367
94907369
94907371
94907373
94907375
94907377
94907379
94907381
94907383
94907385
94907387
94907389
94907391
94907393
94907395
94907397
94907399
94907401
94907403
94907405
94907407
94907409
94907411
94907413
94907415
94907417
94907419
94907421
94907423
94907425
94907427
94907429
94907431
94907433
94907435
94907437
94907439
94907441
94907443
94907445
94907447
94907449
94907451
94907453
94907455
94907457
94907459
94907461
94907463
94907465
94907467
94907469
94907471
94907473
94907475
94907477
94907479
94907481
94907483
94907485
94907487
94907489
94907491
94907493
94907495
94907497
94907499
94907501
94907503
94907505
94907507
94907509
94907511
94907513
94907515
94907517
94907519
94907521
94907523
94907525
94907527
94907529
94907531
94907533
94907535
94907537
94907539
94907541
94907543
94907545
94907547
94907549
94907551
94907553
94907555
94907557
94907559
94907561
94907563
94907565
94907567
94907569
94907571
94907573
94907575
94907577
94907579
94907581
94907583
94907585
94907587
94907589
94907591
94907593
94907595
94907597
94907599
94907601
94907603
94907605
94907607




And so on...



An interesting thing to note here is all the numbers which are creating the problem are odd.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 23 '18 at 10:36

























answered Nov 22 '18 at 16:58









Archit AgrawalArchit Agrawal

113




113












  • Can you give some more context to your answer? What "list" are you taking about?
    – 16num
    Nov 22 '18 at 17:05










  • By 'list', Archit means 'examples of values' and not list as in array. Archit, the code is giving incorrect answer for even values as well - try giving inputs with 4-5 more digits
    – Prabhat Soni
    Nov 23 '18 at 10:50


















  • Can you give some more context to your answer? What "list" are you taking about?
    – 16num
    Nov 22 '18 at 17:05










  • By 'list', Archit means 'examples of values' and not list as in array. Archit, the code is giving incorrect answer for even values as well - try giving inputs with 4-5 more digits
    – Prabhat Soni
    Nov 23 '18 at 10:50
















Can you give some more context to your answer? What "list" are you taking about?
– 16num
Nov 22 '18 at 17:05




Can you give some more context to your answer? What "list" are you taking about?
– 16num
Nov 22 '18 at 17:05












By 'list', Archit means 'examples of values' and not list as in array. Archit, the code is giving incorrect answer for even values as well - try giving inputs with 4-5 more digits
– Prabhat Soni
Nov 23 '18 at 10:50




By 'list', Archit means 'examples of values' and not list as in array. Archit, the code is giving incorrect answer for even values as well - try giving inputs with 4-5 more digits
– Prabhat Soni
Nov 23 '18 at 10:50


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53380537%2falternate-way-of-squaring-a-number%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

'app-layout' is not a known element: how to share Component with different Modules

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

WPF add header to Image with URL pettitions [duplicate]