largenumber

Calculating variance with large numbers

北城余情 提交于 2019-12-02 05:36:13
问题 I haven't really used variance calculation that much, and I don't know quite what to expect. Actually I'm not too good with math at all. I have a an array of 1000000 random numeric values in the range 0-10000. The array could grow even larger, so I use 64 bit int for sum. I have tried to find code on how to calc variance, but I don't know if I get correct output. The mean is 4692 and median is 4533. I get variance 1483780.469308 using the following code: // size is the element count, in this

How to calculate the mod of large exponents?

我与影子孤独终老i 提交于 2019-12-02 03:34:05
For example I want to calculate (reasonably efficiently) 2^1000003 mod 12321 And finally I want to do (2^1000003 - 3) mod 12321. Is there any feasible way to do this? Basic modulo properties tell us that 1) a + b (mod n) is (a (mod n)) + (b (mod n)) (mod n) , so you can split the operation in two steps 2) a * b (mod n) is (a (mod n)) * (b (mod n)) (mod n) , so you can use modulo exponentiation (pseudocode): x = 1 for (10000003 times) { x = (x * 2) % 12321; # x will never grow beyond 12320 } Of course, you shouldn't do 10000003 iterations, just remember that 2 1000003 = 2 * 2 1000002 , and 2

Calculating variance with large numbers

谁都会走 提交于 2019-12-02 00:11:30
I haven't really used variance calculation that much, and I don't know quite what to expect. Actually I'm not too good with math at all. I have a an array of 1000000 random numeric values in the range 0-10000. The array could grow even larger, so I use 64 bit int for sum. I have tried to find code on how to calc variance, but I don't know if I get correct output. The mean is 4692 and median is 4533. I get variance 1483780.469308 using the following code: // size is the element count, in this case 1000000 // value_sum is __int64 double p2 = pow( (double)(value_sum - (value_sum/size)), (double)2

Python 3 strange division

让人想犯罪 __ 提交于 2019-12-01 20:51:49
问题 About half an hour thinking "what am i doing wrong!?" on the 5-lines code.. because Python3 is somehow rounding big integers. Anyone know why there is a problem such: Python2: int(6366805760909027985741435139224001 # This is 7**40. / 7) == 909543680129861140820205019889143 # 7**39 Python3: int(6366805760909027985741435139224001 / 7) == 909543680129861204865300750663680 # I have no idea what this is. 回答1: Python 3 is not "rounding big integers". What it does is that it will return a float

Java - Can't make ProjectEuler 3 Work for a very big number (600851475143)

南笙酒味 提交于 2019-12-01 01:23:27
Resolution: It turns out there is (probably) "nothing wrong" with the code itself; it is just inefficient. If my math is correct, If I leave it running it will be done by Friday, October 14, 2011. I'll let you know! Warning: this may contain spoilers if you are trying to solve Project Euler #3. The problem says this: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? Here's my attempt to solve it. I'm just starting with Java and programming in general, and I know this isn't the nicest or most efficient solution. import java.util

C++ Large Number Arithmetic

这一生的挚爱 提交于 2019-11-30 16:48:20
I'm developing a class for large number arithmetic, it now knows how to do addition, handle cin and cout. It, however has very limited and basic subtraction functionality, and does not know how to handle negative. But that can be easily resolved. My question is this, how to do multiplication. I will detail how it handle cin and cout here. For cin, it will save integers to value[500], for example, 50 will be saved to value[498] and value[499]. BUT NOT value[0] and value[1] For cout, it will scan for the first non-zero value from value[0] to value[499], and then output from that non-zero value

Summing Large Numbers

我的梦境 提交于 2019-11-30 15:16:28
I have being doing some problems on the Project Euler website and have come across a problem. The Question asks,"Work out the first ten digits of the sum of the following one-hundred 50-digit numbers." I am guessing there is some mathematical way to solve this but I was just wondering how numbers this big are summed? I store the number as a string and convert each digit to a long but the number is so large that the sum does not work. Is there a way to hold very large numbers as a variable (that is not a string)? I do not want the code to the problem as I want to solve that for myself. vid I

convert astronomically large numbers into human readable form in C/C++

落爺英雄遲暮 提交于 2019-11-30 06:59:39
问题 My program prints out HUGE numbers - like 100363443, up to a trillion -- and it sort of hard to read them, so I would like to print any number in easy to read form. right now I use printf ("%10ld", number); format I would appreciate a resulting number using printf. Most of my code is c++ yet I don't want to introduce std::cout, as I already have printf thanks 回答1: Use the non-standard apostrophe flag in the printf format string, if you have that option available and don't mind losing a little

Long ints in Fortran

老子叫甜甜 提交于 2019-11-30 06:02:48
问题 I'm trying to work with large numbers (~10^14), and I need to be able to store them and iterate over loops of that length, i.e. n=SOME_BIG_NUMBER do i=n,1,-1 I've tried the usual star notation, kind=8 etc. but nothing seems to work. Then I checked the huge intrinsic function, and the code: program inttest print *,huge(1) print *,huge(2) print *,huge(4) print *,huge(8) print *,huge(16) print *,huge(32) end program inttest produces the number 2147483647 in all cases. Why is this? I'm using

C++ Large Number Arithmetic

情到浓时终转凉″ 提交于 2019-11-29 23:31:16
问题 I'm developing a class for large number arithmetic, it now knows how to do addition, handle cin and cout. It, however has very limited and basic subtraction functionality, and does not know how to handle negative. But that can be easily resolved. My question is this, how to do multiplication. I will detail how it handle cin and cout here. For cin, it will save integers to value[500], for example, 50 will be saved to value[498] and value[499]. BUT NOT value[0] and value[1] For cout, it will