Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (576) Games in Android Showcase (154) games submitted by our members Games in WIP (626) 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 1837 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.

 ClaasJG (38 views) 2015-04-30 20:33:25 Riven (23 views) 2015-04-30 13:25:12 ClaasJG (42 views) 2015-04-27 13:36:51 BurntPizza (49 views) 2015-04-23 03:42:11 theagentd (51 views) 2015-04-22 16:23:07 Riven (61 views) 2015-04-16 10:48:47 Duke0200 (74 views) 2015-04-16 01:59:01 Fairy Tailz (56 views) 2015-04-14 20:13:12 Riven (62 views) 2015-04-12 21:36:37 bus hotdog (87 views) 2015-04-10 02:39:32
 theagentd 25x BurntPizza 19x Spasi 16x kingroka123 11x wessles 11x alwex 11x Hanksha 8x ra4king 7x chrislo27 7x Ecumene 7x Olo 7x kevglass 7x princec 6x Riven 6x trollwarrior1 5x EgonOlsen 5x
 How 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:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27
 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