Alice Community  

Go Back   Alice Community > General Discussion > The Lounge

Reply
 
Thread Tools Display Modes
Solving math problems with Programming
Old
hydude777
Member
 
Status: Offline
Posts: 25
Join Date: Apr 2011
Default Solving math problems with Programming - 02-06-2012, 11:09 PM

programmers!
i need help on a math problem...
is it okay to post here?

Are there any prime numbers with differences of 3?
e.g. 2 and 5 (they're not prime)

is it possible to solve that with programming?


For example to find if 'how many positive integers less than 1000 do not have 7 as their digit'
private int doit()
{
int rwcnt=0;
for (int i=0; i< 1000;i++)
{
string stri = Convert.ToString(i);
if (stri.IndexOf("7") == -1) {rwcnt++;}
}
return rwcnt;
}

rwcnt = 729.
that would work.
   
Reply With Quote
Old
x2495iiii
Super Moderator
 
x2495iiii's Avatar
 
Status: Offline
Posts: 3,508
Join Date: Dec 2008
Location: Somewhere in the Continental U.S.
Default 02-07-2012, 01:48 AM

2 and 5 are prime and are the only prime numbers that are three apart. This is because all prime numbers are odd, and an odd number plus 3 makes an even number. 2 is the only even prime number, meaning two and five are the only prime numbers with a difference of three.


(')>
   
Reply With Quote
Old
hydude777
Member
 
Status: Offline
Posts: 25
Join Date: Apr 2011
Default 02-07-2012, 06:47 AM

oh, okay

that was easy :O

thanks for the explanation x2495iiii !!
   
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2024, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.