MarkdownPad Document

We Chall-Prime Factory-Writeup

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

网站打开较慢,所以把题目放在下方:

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 }

运行结果如下:

根据要求的形式得flag为:10000331000037

2017-2-5 12:40;11

转载于:https://www.cnblogs.com/WangAoBo/p/6367360.html

We Chall-Prime Factory-Writeup相关推荐

  1. 7.Wechall-------------Prime Factory by ch0wch0w(得分2个)

    0x01:问题 题目 题目链接地址 Prime Factory http://www.wechall.net/challenge/training/prime_factory/index.php 0x ...

  2. wechall靶场training系列通关记录

    wechall靶场Training系列通关记录 Training: Get Sourced 第一题很简单,获取藏在网页源代码中的密码.F12查看网页中的注释即可找到答案: Training: Steg ...

  3. 平述factory reset ——从main system到重引导流程

    关于Android或linux的引导流程,网上大都是从开机开始讲述的,或者直接跳过bootloader引导阶段,直接从init进程开始说起.这里我从手机正常运行状态开始,到重启状态以及重启之后的状态略 ...

  4. 强网杯2018 - nextrsa - Writeup

    强网杯2018 - nextrsa - Writeup 原文地址:M4x@10.0.0.55 所有代码均已上传至我的github 俄罗斯套娃一样的rsa题目,基本把我见过的rsa套路出了一遍,值得记录 ...

  5. C++prime读书笔记(二)C++标准库:IO、容器、泛型算法、动态内存

    layout: post title: C++prime读书笔记(二)C++标准库:IO.容器.泛型算法.动态内存 description: C++prime读书笔记(二)C++标准库:IO.容器.泛 ...

  6. 使用JPA进行update操作时,报org.springframework.beans.factory.BeanCreationException: Error creating bean with

    使用JPA进行update操作时,报org.springframework.beans.factory.BeanCreationException: Error creating bean with ...

  7. ccf 最优灌溉(prime模板)

    模板题 #include<bits/stdc++.h> using namespace std; #define INF 0x3f3f3f3f int lowcost[1010]; int ...

  8. usaco Prime Palindromes

    新技能get,可以这样遍历回文数,的确厉害.注意剪枝不然超时. /* ID: jinbo wu LANG:C++ TASK: pprime */ #include <stdio.h> #i ...

  9. 设计模式之简单工厂模式(Simply Factory)摘录

    从设计模式的类型上来说,简单工厂模式是属于创建型模式,又叫静态工厂方法(Static Factory Method)模式,但不属于23种GOF设计模式之一.简单工厂模式是由一个工厂对象决定创建出哪一种 ...

最新文章

  1. DeepMind发69页长文掀开AlphaZero的黑盒:神经网络学到的知识和人类基本相似!
  2. 红帽集群套件RHCS
  3. java 对象初始化属性,JAVA中类属性的初始化
  4. 【Python爬虫】写个爬虫爬取自己的博客,可以刷访问量
  5. python学习-代码调试(通过print调试、通过pdb调试、通过编译器调试(断点调试))
  6. @JsonFormat失效解决
  7. 设计模式--请参阅本质
  8. (81)Vivado实现约束过程
  9. php 己遏急背季磐,PHP防止SQL攻击教程
  10. XSS-Game level 6
  11. SpringBoot+Vue项目个性化音乐推荐系统
  12. 高斯滤波器原理及其实现
  13. 易语言 自动更新替换自身 的方法
  14. android expandablelistview横向,完美实现ExpandableListView二级分栏效果
  15. 华南师范大学 计算机学院 赵,罗子颖 计算机学院
  16. 酒友app软件开源平台
  17. vue2打包兼容ie11白屏报错问题汇总
  18. SCI、EI、IEEE和中文期刊在查询中有什么区别?
  19. 代码整洁之道,不止于程序员需要的职业素养
  20. 阿里电话面试总结(人生第一次面试!!)

热门文章

  1. Android实战技巧之十一:Android Studio和Gradle
  2. 小米3 开发人员选项
  3. 合工大建筑和计算机专业哪个好,合肥工业大学最好的专业是什么(10大热门专业排名)...
  4. #mysql50#_#mysql50#.ssh设个啥数据库?
  5. 手机息屏后停止_手机息屏还能这样玩?华为这几个隐藏小功能快学起来
  6. Git错误:fatal: Not a git repository (or any of the parent directories)解决方法
  7. 基于DSP/BIOS和NDK的嵌入式网络操作系统设计方案
  8. 计算机文档里的东西可以删吗,电脑c盘哪些文件可以删除
  9. Python 存储字符串时是如何节省空间的?
  10. 2019年,为什么Web前端工程师薪资越来越高?