当前位置: 游戏平台 > 互联网科技 > 正文

We Chall-Prime Factory-Writeup,writeup

时间:2019-11-13 22:35来源:互联网科技
Prime Factory (Training, Math) Your task is simple: Find the first two primes above 1 million, whose separate digit sums arealso prime. As example take 23, which is a prime whose digit sum, 5, is alsoprime. The solution is the concatination

Prime Factory (Training, Math)

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

忽略正是找到七个数,那七个数切合:是超乎1000000的质数,并且数字的每壹个人加起来仍然为质数,如:23是质数,2+3=5仍然为质数;

因为从没时间的范围,所以用C++写了一个强力循环的代码:

 1 #include<iostream>
 2 #include<cmath>
 3 using namespace std;
 4 typedef long long LL;
 5 const LL MILLION = 1000000;
 6 
 7 bool IsPrime_1(LL num)
 8 {
 9     for(int i = 2; i <= sqrt(num); i++)
10         if(!(num % i))
11             return 0;//num不是质数
12 
13     return 1;//num是质数
14 }
15 
16 bool IsPrime_2(LL num)
17 {
18     LL sum = 0;
19     while(num)
20     {
21         sum += num % 10;
22         num /= 10;
23     }
24 
25     if(IsPrime_1(sum))
26         return 1;//各位数字的和仍为质数
27     else
28         return 0;
29 }
30 
31 int main()
32 {
33 //    LL num;
34 //    cin>>num;
35 //    if(IsPrime_1(num))
36 //        cout<<1<<endl;
37 //    if(IsPrime_2(num))
38 //        cout<<2<<endl;
39     for(LL i = MILLION+1 , cnt = 0 ; cnt < 2 ; i++)
40     {
41         if(IsPrime_1(i))
42             if(IsPrime_2(i))
43             {
44                 cnt++;
45                 cout<<i<<endl;
46             }
47     }
48 
49     return 0;
50 }

 

运行结果如下:
图片 1
依靠需求的款型得flag为:10000331000037

令:因ABO暂面生flag,所以用了较麻烦的C++,同一时间因为从没界依期间,所以写了暴力循环的代码,以往熟习python之后,会更新更为简练的python代码;

 

 

 

 

 

2017-2-5 12:40;11

Chall-Prime Factory-Writeup,writeup 马克downPad Document We Chall-Prime Factory-Writeup 标题链接: 网站打...

We Chall-Prime Factory-Writeup,writeup

MarkdownPad Document

We Chall-Prime Factory-Writeup

题目链接:http://www.wechall.net/challenge/training/prime_factory/index.php

网址展开异常的慢,所以把标题放在下方:

编辑:互联网科技 本文来源:We Chall-Prime Factory-Writeup,writeup

关键词: