(Problem 35)Circular primes
The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.
There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.
How many circular primes are there below one million?
题目大意:
我们称197为一个循环质数,因为它的所有轮转形式: 197, 971和719都是质数。
100以下有13个这样的质数: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, 和97.
100万以下有多少个循环质数?
- //(Problem 35)Circular primes
- // Completed on Fri, 26 Jul 2013, 06:17
- // Language: C
- //
- // 版权所有(C)acutus (mail: acutus@126.com)
- // 博客地址:http://www.cnblogs.com/acutus/#include<stdio.h>
- #include<math.h>
- #include<string.h>
- #include<ctype.h>
- #include<stdlib.h>
- #include<stdbool.h>
- bool isprim(int n)
- {
- int i=;
- for(; i*i<n; i++)
- {
- if(n%i==) return false;
- }
- return true;
- }
- bool circular_prime(int n)
- {
- int i,j,flag=;
- char s[];
- int sum=;
- sprintf(s,"%d",n);
- int len=strlen(s);
- for(i=; i<len; i++)
- {
- if(s[i]!='' && s[i]!='' && s[i]!='' && s[i]!='')
- return false;
- }
- for(i=; i<len; i++)
- {
- for(j=i; j<i+len-; j++)
- {
- sum+=s[j%len]-'';
- sum*=;
- }
- sum+=s[j%len]-'';
- if(!isprim(sum)) return false;
- sum=;
- }
- return true;
- }
- int main()
- {
- int sum=; //已包含2,3,5,7
- for(int i=; i<; i++)
- {
- if(circular_prime(i))
- sum++;
- }
- printf("%d\n",sum);
- return ;
- }
Answer:
|
55 |
(Problem 35)Circular primes的更多相关文章
- (Problem 47)Distinct primes factors
The first two consecutive numbers to have two distinct prime factors are: 14 = 2 7 15 = 3 5 The fi ...
- (Problem 37)Truncatable primes
The number 3797 has an interesting property. Being prime itself, it is possible to continuously remo ...
- (Problem 49)Prime permutations
The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual ...
- (Problem 29)Distinct powers
Consider all integer combinations ofabfor 2a5 and 2b5: 22=4, 23=8, 24=16, 25=32 32=9, 33=27, 34=81, ...
- (Problem 73)Counting fractions in a range
Consider the fraction, n/d, where n and d are positive integers. If nd and HCF(n,d)=1, it is called ...
- (Problem 42)Coded triangle numbers
The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangl ...
- (Problem 41)Pandigital prime
We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly o ...
- (Problem 70)Totient permutation
Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number ...
- (Problem 74)Digit factorial chains
The number 145 is well known for the property that the sum of the factorial of its digits is equal t ...
随机推荐
- POJ 1222 EXTENDED LIGHTS OUT(高斯消元)
[题目链接] http://poj.org/problem?id=1222 [题目大意] 给出一个6*5的矩阵,由0和1构成,要求将其全部变成0,每个格子和周围的四个格子联动,就是说,如果一个格子变了 ...
- Javascript数组的声明
var cars=new Array(); cars[0]="Audi"; cars[1]="BMW"; cars[2]="Volvo"; ...
- 深入解读JavaScript面向对象编程实践
面向对象编程是用抽象方式创建基于现实世界模型的一种编程模式,主要包括模块化.多态.和封装几种技术.对JavaScript而言,其核心是支持面向对象的,同时它也提供了强大灵活的基于原型的面向对象编程能力 ...
- activity的横屏和竖屏设置
主要在清单文件这样配置: <application android:allowBackup="true" android:icon="@drawable/ic_la ...
- Insert into a Cyclic Sorted List
Given a node from a cyclic linked list which has been sorted, write a function to insert a value int ...
- 经典阅读-《Effective C++》Item1:视C++为一个联邦语言
C++已经是个多重范型编程语言(multiparadigm programming language),一个同时支持过程形式(procedural).面向对象形式(object-oriented).泛 ...
- 自定义jquery表格插件
以前一直都是再用easyui插件来实现各种功能,但是easyui太过于庞大,使用越多对服务器负载影响越大. 基于此,在模仿easyui的dataGrid表格插件的同时,自己去封装了一个.实现了基本的j ...
- <转> Python的优雅技巧
枚举 不要这么做: 全选复制放进笔记 i = 0 for item in iterable: print i, item i += 1 而是这样: 全选复制放进笔记 for i, item in en ...
- 关于js的一些关键知识点(call,apply,callee, caller,clourse,prototypeChain)
可能不少学习javascript在使用call,apply,callee时会感到困惑,以下希望对于你有所帮助: 1.~~~call ,apply是函数(函数对象)的方法:callee是函数argume ...
- 【双模卡的相关知识】解SIM卡前需要知道的信息(SIM年分和厂商识别)
<ignore_js_op> 二.SIM版本问题SIM卡的版本有两种说法,一是有些是制造厂制定的,二是电信公司的制定.下面以移动为例,目前我们手里的SIM有几种版本:v0.v1.v2.v3 ...