[VA] SRC #013 - Pi Day 2023 Special
|
03-29-2023, 01:16 AM
Post: #30
|
|||
|
|||
RE: [VA] SRC #013 - Pi Day 2023 Special
.
Hi, all, Adding to this: Valentin Albillo Wrote:Alas, as J-F discovered, it does not, possibly because of some rounding error, but the solution is quite simple because the only operations which can result in such errors are the square root (which is innocent) and divisions. A little examination reveals that the culprit is IP(T/(K*K)) at line 2, and changing it to (T DIV (K*K)), like this: [...] Indeed IP(T/(K*K)) and T DIV (K*K), which would appear at first sight to be equivalent, do really differ at times (though very rarely and for large values of T, it seems,) when the former's rounding does not match the latter's truncation. A trivial program I wrote (relatively) quickly finds all mismatches for various very large integer T and for K from 2 to IP(√T) (i.e. ~ one million possible cases for the first eight values of T listed):
----------------------------------------------------------- 999,999,999,999 31 instances 2, 5, 8, 16, 20, ... 999,999,999,998 19 instances 2, 3, 8, 20, 25, ... 999,999,999,997 12 instances 3, 8, 25, 80, ... 999,999,999,996 3 instances 3, 3125, 31250, ... 999,999,999,995 3 instances 2, 3, 254 999,999,999,994 1 instance 254 999,999,999,993 1 instance 254 999,999,999,992 0 instances - 99,999,999,999 0 instances - Doing the same with T = 999,999,999,998, there's just 19 instances reported instead of 31, and with T = 999,999,999,997 just 12. By the time T equals 999,999,999,995, a mere 3 faulty instances remain (namely for K = 2, 3 and 254), then 999,999,999,994 and 999,999,999,993 have just the one mismatch (in a million !) and for 999,999,999,992 and below there seems to be none. Also, as expected, running this small program for input values with less than 12 digits, say T = 99,999,999,999 instead, i.e. 1E11 - 1, no instances of mismatches appear at all, and probably the same happens for all smaller T. V. All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)