Java-Gaming.org Hi !
 Featured games (83) games approved by the League of Dukes Games in Showcase (593) Games in Android Showcase (168) games submitted by our members Games in WIP (647) 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 1896 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.

 Riven (8 views) 2015-07-03 11:22:16 deepthought (40 views) 2015-06-30 15:39:44 deepthought (44 views) 2015-06-30 15:39:09 deepthought (54 views) 2015-06-30 15:36:52 Za\'Anzabar (24 views) 2015-06-29 05:44:54 TritonDreyja (41 views) 2015-06-24 17:10:40 CopyableCougar4 (39 views) 2015-06-23 00:34:45 BurntPizza (43 views) 2015-06-21 20:36:46 cookiecompiler (85 views) 2015-06-11 15:42:53 cookiecompiler (48 views) 2015-06-11 15:41:14
 princec 34x wessles 24x BurntPizza 19x opiop65 18x CopyableCougar4 18x theagentd 15x Riven 15x nsigma 15x KaiHH 14x EgonOlsen 14x SauronWatchesYou 11x KevinWorkman 11x sunburn 11x Archive 10x NegativeZero 10x ags1 10x
 How 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:21Resources for WIP gamesby kpars2014-12-18 10:26:14
 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