Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (777) Games in Android Showcase (231) games submitted by our members Games in WIP (856) 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 3190 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

 hadezbladez (289 views) 2018-11-16 13:46:03 hadezbladez (157 views) 2018-11-16 13:41:33 hadezbladez (289 views) 2018-11-16 13:35:35 hadezbladez (71 views) 2018-11-16 13:32:03 EgonOlsen (2150 views) 2018-06-10 19:43:48 EgonOlsen (2152 views) 2018-06-10 19:43:44 EgonOlsen (1364 views) 2018-06-10 19:43:20 DesertCoockie (1983 views) 2018-05-13 18:23:11 nelsongames (1600 views) 2018-04-24 18:15:36 nelsongames (2248 views) 2018-04-24 18:14:32
 Deployment and Packagingby mudlee2018-08-22 18:09:50Java Gaming Resourcesby gouessej2018-08-22 08:19:41Deployment and Packagingby gouessej2018-08-22 08:04:08Deployment and Packagingby gouessej2018-08-22 08:03:45Deployment and Packagingby philfrei2018-08-20 02:33:38Deployment and Packagingby philfrei2018-08-20 02:29:55Deployment and Packagingby philfrei2018-08-19 23:56:20Deployment and Packagingby philfrei2018-08-19 23:54:46
 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