Java-Gaming.org Hi !
 Featured games (91) games approved by the League of Dukes Games in Showcase (756) Games in Android Showcase (229) games submitted by our members Games in WIP (842) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 prime number decomposition (math)  (Read 3038 times) 0 Members and 1 Guest are viewing this topic.
Kommi

Junior Devvie

All opinions will be lined up and shot!

 « Posted 2005-04-05 21:03:09 »

ok I need help coding this up in Java. I really dont understand any explanation of how exaclty a prime number decomposition algorithm works (in math terms). Does anyone know anything about this? Can you help me figure out a Java algo for it?

Kommi
DanoruX

Senior Newbie

Java games rock!

 « Reply #1 - Posted 2005-04-06 11:05:22 »

To find out if a number is a prime number you devide it by every integer starting from 2 up to the square root of the nuber you're analyzing. Of course, the program will run a little faster is you skip as many integers as possible (like storing previously found primes in an arraylist and only deviding by those instead of every integer).

in it's simplest form:

 1  2  3  4 `if (number % dividebythisnumber == 0){    // number is a prime.}`
CaffeineOverdose

Senior Newbie

Java games rock!

 « Reply #2 - Posted 2005-04-08 01:43:58 »

The method will work. It sounds very tedious and will take awhile if you use very large number, but unless you are checking to see if special types of numbers (i.e. (2^n)-1 ) are prime there isn't much else you could do.
DanoruX

Senior Newbie

Java games rock!

 « Reply #3 - Posted 2005-04-08 16:32:16 »

couple of things you should know...

- all primes end with either 1,3,7 or 9
- the last digit is evenly distibuted. I tried it with 100000 primes, and all last digits occured 25000 +- 5 times.
Hansdampf

Senior Devvie

Projects: 3

too offending?

 « Reply #4 - Posted 2005-04-08 20:39:00 »

Quote
- all primes end with either 1,3,7 or 9

5

lots of sillystupid games: http://www.emaggame.com
Malohkan

Senior Devvie

while (true) System.out.println("WOO!!!!");

 « Reply #5 - Posted 2005-04-08 23:57:58 »

store them in an array as you create them.  Store 1, 3, 5, 7, 11 in the first indexes and then those rules will suit you fine

GameLizard.com
Play Rimscape!    |    Play Conquer!
DanoruX

Senior Newbie

Java games rock!

 « Reply #6 - Posted 2005-04-11 12:16:43 »

Quote

5

That's the one exception T_T

JGO Wizard

Medals: 19
Projects: 19

Mojang Specifications

 « Reply #7 - Posted 2005-04-11 12:19:42 »

2

Play Minecraft!
Pages: [1]
 ignore  |  Print

 DesertCoockie (52 views) 2018-05-13 18:23:11 nelsongames (83 views) 2018-04-24 18:15:36 nelsongames (74 views) 2018-04-24 18:14:32 ivj94 (759 views) 2018-03-24 14:47:39 ivj94 (87 views) 2018-03-24 14:46:31 ivj94 (643 views) 2018-03-24 14:43:53 Solater (102 views) 2018-03-17 05:04:08 nelsongames (184 views) 2018-03-05 17:56:34 Gornova (426 views) 2018-03-02 22:15:33 buddyBro (1086 views) 2018-02-28 16:59:18
 Java Gaming Resourcesby philfrei2017-12-05 19:38:37Java Gaming Resourcesby philfrei2017-12-05 19:37:39Java Gaming Resourcesby philfrei2017-12-05 19:36:10Java Gaming Resourcesby philfrei2017-12-05 19:33:10List of Learning Resourcesby elect2017-03-13 14:05:44List of Learning Resourcesby elect2017-03-13 14:04:45SF/X Librariesby philfrei2017-03-02 08:45:19SF/X Librariesby philfrei2017-03-02 08:44:05
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org