Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (603) Games in Android Showcase (171) games submitted by our members Games in WIP (652) 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 1923 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: 16
Projects: 19

Mojang Specifications

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

2

Play Minecraft!
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 SHC (11 views) 2015-08-01 03:58:20 Jesse (17 views) 2015-07-29 04:35:27 Riven (38 views) 2015-07-27 16:38:00 Riven (19 views) 2015-07-27 15:35:20 Riven (22 views) 2015-07-27 12:26:13 Riven (12 views) 2015-07-27 12:23:39 BurntPizza (32 views) 2015-07-25 00:14:37 BurntPizza (44 views) 2015-07-24 22:06:39 BurntPizza (25 views) 2015-07-24 06:06:53 NoxInc (32 views) 2015-07-22 22:16:53
 theagentd 51x wessles 45x basil_ 35x KaiHH 26x orangepascal 26x ags1 21x Riven 19x mooman219 17x bornander 14x KudoDEV 13x Jesse 11x princec 11x CelestialCreator 11x klaus 11x Zaneris 9x pquiring 8x
 List of Learning Resourcesby gouessej2015-07-09 11:29:36How Do I Expand My Game?by bashfrog2015-06-14 11:34:43List of Learning Resources2015-05-31 05:37:30Intersection Methodsby Roquen2015-05-29 08:19:33List of Learning Resources2015-05-05 10:20:32How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21
 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