Project Euler 35 Circular primes
题意:197被称为圆周素数,因为将它逐位旋转所得到的数:197/971和719都是素数。小于100的圆周素数有十三个:2、3、5、7、11、13、17、31、37、71、73、79和97。小于一百万的圆周素数有多少个?
/*************************************************************************
> File Name: euler035.c
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年06月25日 星期日 18时56分56秒
************************************************************************/
#include <stdio.h>
#include <math.h>
#include <inttypes.h>
#define MAX_N 10000000
int32_t prime[MAX_N] = {0};
void init_prime(){
for(int i = 2 ; i * i < MAX_N ; i++) {
if( prime[i] == 0 ) {
for(int j = 2 * i ; j < MAX_N ; j += i) prime[j] = 1;
}
}
}
bool IsCircularNumber(int32_t x){
if (prime[x] != 0) return false;
int32_t t = x , d , h;
d = (int32_t)floor(log10(x) + 1);
h = (int32_t)pow(10 , d - 1);
for(int32_t i = 0 ; i < d - 1 ; i++) {
t = (t / h) + (t % h) * 10;
if (prime[t] != 0) return false;
}
return true;
}
int32_t main() {
init_prime();
int32_t cnt = 0;
for(int32_t i = 2 ; i * 10 <= MAX_N ; i++) {
if( IsCircularNumber(i) ) cnt++;
}
printf("%d\n",cnt);
return 0;
}
Project Euler 35 Circular primes的更多相关文章
- Project Euler 27 Quadratic primes( 米勒测试 + 推导性质 )
题意: 欧拉发现了这个著名的二次多项式: f(n) = n2 + n + 41 对于连续的整数n从0到39,这个二次多项式生成了40个素数.然而,当n = 40时402 + 40 + 41 = 40( ...
- Project Euler 21 Distinct primes factors( 整数因子和 )
题意: 记d(n)为n的所有真因数(小于n且整除n的正整数)之和. 如果d(a) = b且d(b) = a,且a ≠ b,那么a和b构成一个亲和数对,a和b被称为亲和数. 例如,220的真因数包括1. ...
- Project Euler 47 Distinct primes factors( 筛法记录不同素因子个数 )
题意: 首次出现连续两个数均有两个不同的质因数是在: 14 = 2 × 715 = 3 × 5 首次出现连续三个数均有三个不同的质因数是在: 644 = 22 × 7 × 23645 = 3 × 5 ...
- Project Euler 37 Truncatable primes
题意:3797有着奇特的性质.不仅它本身是一个素数,而且如果从左往右逐一截去数字,剩下的仍然都是素数:3797.797.97和7:同样地,如果从右往左逐一截去数字,剩下的也依然都是素数:3797.37 ...
- Project Euler 58: Spiral primes
从一开始按以下方式逆时针旋转,可以形成一个边长为七的正方形螺旋: 一个有趣的现象是右下对角线上都有一个奇完全平方数,但是更有趣的是两条对角线上的十三个数中有八个数是素数(已经标红),也就是说素数占比为 ...
- (Problem 35)Circular primes
The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, ...
- Project Euler 44: Find the smallest pair of pentagonal numbers whose sum and difference is pentagonal.
In Problem 42 we dealt with triangular problems, in Problem 44 of Project Euler we deal with pentago ...
- Python练习题 039:Project Euler 011:网格中4个数字的最大乘积
本题来自 Project Euler 第11题:https://projecteuler.net/problem=11 # Project Euler: Problem 10: Largest pro ...
- Python练习题 038:Project Euler 010:两百万以内所有素数之和
本题来自 Project Euler 第10题:https://projecteuler.net/problem=10 # Project Euler: Problem 10: Summation o ...
随机推荐
- 洛谷—— P1784 数独
https://www.luogu.org/problem/show?pid=1784 题目描述 数独是根据9×9盘面上的已知数字,推理出所有剩余空格的数字,并满足每一行.每一列.每一个粗线宫内的数字 ...
- 洛谷 P3004 [USACO10DEC]宝箱Treasure Chest
P3004 [USACO10DEC]宝箱Treasure Chest 题目描述 Bessie and Bonnie have found a treasure chest full of marvel ...
- Ajax json 数据格式
ajax : 是么是同步 什么事异步 同步现象:客户端发送请求到服务端,当服务端返回响应之前,客户端都处于等待卡死状态. 异步现象:客户端发送请求到服务器端,无论服务器是否返回,客户端都可以随意做其他 ...
- sendfile学习
参考 https://zhuanlan.zhihu.com/p/20768200?refer=auxten 而成本很多时候的体现就是对计算资源的消耗,其中最重要的一个资源就是CPU资源. Sendfi ...
- 例题 2-1 aabb 2-2 3n+1问题
例题2-1 aabb 输出全部形如aabb的四位全然平方数(即前两位数字相等,后两位数字也相等) #include <stdio.h> #include <stdlib.h> ...
- S 禁止F12和右键操作控制台,兼容各浏览器
document.oncontextmenu = function () { return false; }; document.onkeydown = function () { ...
- Service启动模式
Service简单介绍 Service表示服务.是Android系统的核心组件之中的一个. Service的本质是一个继承了android.app.Service的java类: ...
- MySQL数据库管理(二)单机环境下MySQL Cluster的安装
上文<MySQL数据库管理(一)MySQL Cluster集群简单介绍>对MySQL Cluster集群做了简要介绍.本文将教大家一步步搭建单机环境下的MySQL数据库集群. 一.单机环境 ...
- vmware mac 分辨率设置
1.安装vmware tool 2.关闭虚拟机,在设置中找到显示器项 3.选中“加速3D图形” 4.在监视器中,选中 指定监视器设置,使用任意分辨率 5.如果没有可用分辨率,手动输入,例如 1680* ...
- 自己实现的一个 .net 缓存类(原创)
public class CacheContainer { private static Hashtable ht = new Hashtable(); /// <summary> /// ...