/**
* @(#)Sophie.java
*
*
* @author
* @version 1.00 2011/2/17
*/
import java.util.*;
public class Sophie {
/**
* Creates a new instance of <code>Sophie</code>.
*/
public Sophie() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
String output="";
if(t>=1 &&t<=20){
for(int i=0;i<t;i++){
int count=0;
int n=sc.nextInt();
if(n>=1 && n<=10000){
for(int j=2;j<=n;j++){
if(isPrime(j)&&isPrime((2*j)+1)){
count++;
}
}
output+="Case #" +(i+1)+": " + count+"\n";
}
else{
return;
}
}
}
else{
return;
}
System.out.println();
System.out.println(output);
}
public static boolean isPrime(int n){
if(n==0){
return false;
}
for(int i=2;i<=n/2;i++){
if(n%i==0){
return false;
}
}
return true;
}
}
//
1b.pdf (49.18K)
Number of downloads: 35
This post has been edited by macosxnerd101: 22 February 2011 - 11:04 AM
Reason for edit:: Please use code tags

New Topic/Question
Reply




MultiQuote







|