WeChall_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

解题:

素数打表,依次从小到达剔除素数的倍数的数。

def allsum(x):
    sum = 0
    while x:
        sum += x%10
        x //= 10
    return sum

total = 2000000
prime = []
a = [1 for i in range(total)]
for i in range(2,total):
    if a[i]:
        prime.append(i)
        time = 2
        while 1:
            num = time*i
            if num >= total:
                break
            a[num] = 0
            time += 1

find = 0
for i in range(1000000,total):
    if i in prime and allsum(i) in prime:
        print(i)
        find += 1
        if find == 2:
            break
时间: 2024-08-06 00:12:39

WeChall_Prime Factory (Training, Math)的相关文章

WeChall_Prime Factory (Training, Math)Training: WWW-Robots (HTTP, Training)

In this little training challenge, you are going to learn about the Robots_exclusion_standard.The robots.txt file is used by web crawlers to check if they are allowed to crawl and index your website or only parts of it.Sometimes these files reveal th

We Chall-Prime Factory-Writeup

MarkdownPad Document html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label

2017 UESTC Training for Math

A    sg博弈水题 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i) #define mes(a,b) memset(a,b,sizeof

Android官方开发文档Training系列课程中文版:手势处理之滚动动画及Scroller

原文地址:http://android.xsoftlab.net/training/gestures/scroll.html 在Android中,滑动经常由ScrollView类来实现.任何超出容器边界的布局都应该将自己内嵌在ScrollView中,以便提供可滚动的视图效果.自定义滚动只有在特定的场景下才会被用到.这节课将会描述这样一种场景:使用scroller显示一种可滚动的效果. 你可以使用Scroller或者OverScroller来收集一些滑动动画所需要的数据.这两个类很相似,但是Ove

Android官方开发文档Training系列课程中文版:手势处理之ViewGroup的事件管理

原文地址:https://developer.android.com/training/gestures/viewgroup.html 在ViewGroup中处理触摸事件要格外小心,因为在ViewGroup中有很多子View,而这些子View对于不同的触摸事件来说是不同的目标.要确保每个View都正确的接收了相应的触摸事件. 在ViewGroup中拦截触摸事件 onInterceptTouchEvent()方法会在触摸事件到达ViewGroup的表面时调用,这包括内部的子View.如果onInt

Deep Learning in a Nutshell: History and Training

Deep Learning in a Nutshell: History and Training This series of blog posts aims to provide an intuitive and gentle introduction to deep learning that does not rely heavily on math or theoretical constructs. The first part in this series provided an

简单?工?厂模式 (Simple Factory Pattern)

@interface ViewController () { Shape *_shape; } @end @implementation ViewController - (void)loadView { //设置画板 self.view=[[SimpleDrawBoard alloc]init]; self.view.backgroundColor=[UIColor whiteColor]; } - (void)viewDidLoad { [super viewDidLoad]; } - (v

POJ3735 Training little cats DP,矩阵快速幂,稀疏矩阵优化

题目大意是,n只猫,有k个动作让它们去完成,并且重复m次,动作主要有三类gi,ei,s i j,分别代表第i只猫获得一个花生,第i只猫吃掉它自己所有的花生,第i只和第j只猫交换彼此的花生.k,n不超过100,m不超过1000,000,000,计算出最后每只猫还剩下多少个花生. 我们假设一个n维向量P,每个分量的值代表这n只猫所拥有的花生数,那么对于gi操作其实就是在第i维分量上加上1:对于ei,那就是在第i维分量上乘以0,说到这里,有木有感觉这很像3D坐标转化中的平移矩阵和缩放矩阵?没错,就是这

angularJs 自定义服务 provide 与 factory 的区别

<!DOCTYPE html> <html lang="en" ng-app="myApp"> <head> <meta charset="UTF-8" /> <title>Document</title> <script src="angular.min.js" ></script> <script type="t