0x01:问题
题目 | 题目链接地址 |
---|---|
Prime Factory | http://www.wechall.net/challenge/training/prime_factory/index.php |
0x02:WR
提示 | 提示 | 解题步骤 |
---|---|---|
Your task is simple:Find the first two primes above 1 million, whose separate digit sums are also prime.As example take 23, which is a prime whose digit sum, 5, is also prime.The solution is the concatination of the two numbers, | Example: If the first number is 1,234,567 and the second is 8,765,432,your solution is 12345678765432 | 运行一个java代码,算出质数。注意,下面的代码,要对应的包 |
package First; //注意这条,代码对应着你这个类的包。
public class First_100w {
public static void main(String[] args){
int flag=0;
StringBuilder ss=new StringBuilder("");
for(int i=1000001;;i=i+2){
if(isPrime(i)&&isPrimeToo(i)){
System.out.println(i);
flag++;
ss.append(i);
}
if(flag==2){
System.out.println(ss);
break;
}
}
}
public static boolean isPrime(int a){
int mid=(int)(Math.sqrt(a));
for(int i=2;i<=mid;i++){
if(a%i==0){
return false;
}
}
return true;
}
public static boolean isPrimeToo(int a){
int sum=0;
while(a!=0){
sum+=a%10;
a=a/10;
}
return isPrime(sum);
}
}
//注意:该代码为借鉴的!!!
0x03:passwd/flag
passwd:10000331000037