number-theory

Converting a number to base 64

风流意气都作罢 提交于 2019-11-28 06:09:13
问题 So I am trying to program (in Python 3 without strings) this cool project that I found. Return the 6-character string representation of the 36-bit number n as a base-64 number in reverse order where the order of the 64 numerals is: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-+ For example, encode(0) → '000000' encode(9876543210) → 'gR1iC9' encode(68719476735) → '++++++' What I have so far is: def encode(n): SYM = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7':

Factorization of an integer

亡梦爱人 提交于 2019-11-27 23:03:21
While answering another, I stumbled over the question how I actually could find all factors of an integer number without the Symbolic Math Toolbox . For example: factor(60) returns: 2 2 3 5 unique(factor(60)) would therefore return all prime-factors, "1" missing. 2 3 5 And I'm looking for a function which would return all factors ( 1 and the number itself are not important, but they would be nice) Intended output for x = 60 : 1 2 3 4 5 6 10 12 15 20 30 60 I came up with that rather bulky solution, apart from that it probably could be vectorized, isn't there any elegant solution? x = 60; P =

How does this prime number test in Java work?

为君一笑 提交于 2019-11-27 18:19:32
问题 The code snippet below checks whether a given number is a prime number. Can someone explain to me why this works? This code was on a study guide given to us for a Java exam. public static void main(String[] args) { int j = 2; int result = 0; int number = 0; Scanner reader = new Scanner(System.in); System.out.println("Please enter a number: "); number = reader.nextInt(); while (j <= number / 2) { if (number % j == 0) { result = 1; } j++; } if (result == 1) { System.out.println("Number: " +

finding a^b^c^… mod m

左心房为你撑大大i 提交于 2019-11-27 18:10:35
I would like to calculate: a b c d . . . mod m Do you know any efficient way since this number is too big but a , b , c , ... and m fit in a simple 32-bit int. Any Ideas? Caveat: This question is different from finding a b mod m. Also please note that a b c is not the same as (a b ) c . The later is equal to a bc . Exponentiation is right-associative. Tacet The answer does not contain full formal mathematical proof of correctness. I assumed that it is unnecessary here. Besides, it would be very illegible on SO, (no MathJax for example). I will use (just a little bit) specific prime

Parallel Algorithms for Generating Prime Numbers (possibly using Hadoop's map reduce)

£可爱£侵袭症+ 提交于 2019-11-27 13:17:43
Generating Prime numbers is a toy problem that I often attempt from time to time, especially when experimenting with a new programming language, platform or style. I was thinking of attempting to write a Prime Number Generation algorithm or a Prime Number Test Algorithm using Hadoop (Map Reduce). I thought I'd post this question to get tips, references, to algorithms, approaches. Although my primary interest is a Map Reduce based algorithm I wouldn't mind looking at new Hadoop programming models or for example looking at using PiCloud I have seems some interesting questions here on Prime

finding a^b^c^… mod m

五迷三道 提交于 2019-11-26 19:19:53
问题 I would like to calculate: a b c d . . . mod m Do you know any efficient way since this number is too big but a , b , c , ... and m fit in a simple 32-bit int. Any Ideas? Caveat: This question is different from finding a b mod m. Also please note that a b c is not the same as (a b ) c . The later is equal to a bc . Exponentiation is right-associative. 回答1: The answer does not contain full formal mathematical proof of correctness. I assumed that it is unnecessary here. Besides, it would be

Parallel Algorithms for Generating Prime Numbers (possibly using Hadoop's map reduce)

亡梦爱人 提交于 2019-11-26 16:17:21
问题 Generating Prime numbers is a toy problem that I often attempt from time to time, especially when experimenting with a new programming language, platform or style. I was thinking of attempting to write a Prime Number Generation algorithm or a Prime Number Test Algorithm using Hadoop (Map Reduce). I thought I'd post this question to get tips, references, to algorithms, approaches. Although my primary interest is a Map Reduce based algorithm I wouldn't mind looking at new Hadoop programming