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的更多相关文章

  1. (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 ...

  2. (Problem 37)Truncatable primes

    The number 3797 has an interesting property. Being prime itself, it is possible to continuously remo ...

  3. (Problem 49)Prime permutations

    The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual ...

  4. (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, ...

  5. (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 ...

  6. (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 ...

  7. (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 ...

  8. (Problem 70)Totient permutation

    Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number ...

  9. (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 ...

随机推荐

  1. CCNA实验(10) -- Access List

    使用包过滤技术在路由器上读取三层及四层报头的信息如源地址.目的地址.源端口.目的端口根据预先定义好的规则对包进行过滤 三种类型:1.标准ACL:表号范围1-99或1300-1999.仅对源IP地址进行 ...

  2. CCNA实验(7) -- NAT

    1.静态NAT2.动态NAT3.复用内部全局地址的NAT(PAT) enableconf tno ip do loenable pass ciscoline con 0logg syncexec-t ...

  3. 重拾CSS基础—开篇

    由来 从事软件行业一晃也5年有余,之间参与过若干个基于web的项目,所以javascript和Html基本已经相当熟悉,最近对于web前端开发比较关注,分析后发现CSS的确是自己的弱项,于是决定再加强 ...

  4. struts Value Stack 值栈

    首先声明:本文是从博客园博友的文章转载过来的,感觉说的不错.在此附上地址:http://www.cnblogs.com/jerryxing/archive/2012/04/23/2467299.htm ...

  5. 《Effective C++》:条款48:理解力template 元编程

    Template metaprogramming(TMP,模板元编程)这是写template-based C++规划.编译过程.template metaprogramming随着C++写模板程序,化 ...

  6. c 结构体struct

    struct 定义初始化 #include<stdio.h> typedef struct stuInfo { ]; //姓名 int stuId; //学号 int age; //年龄 ...

  7. MicroStrategy笔试

    1. coding判定二叉树是否是有序二叉树 2. 一个有序数组A(buffer足够大),和一个有序数组B,设计算法,merge两个数组后有序,不使用任何额外的内存空间 3. 100个点灯问题,初始状 ...

  8. 通过读取excel数据和mysql数据库数据做对比(二)-代码编写测试

    通过上一步,环境已搭建好了. 下面开始实战, 首先,编写链接mysql的函数conn_sql.py import pymysql def sql_conn(u,pwd,h,db): conn=pymy ...

  9. 一个帝国cms [!--show.listpage--] css样式

    1.在分页位置加<div class="pagepage">[!--show.listpage--]</div> </div>这个标签 2.在需 ...

  10. java.lang.VerifyError: Inconsistent stackmap frames at branch target

    -XX:-UseSplitVerifier解决. 附带网址:http://stackoverflow.com/questions/12774672/java-7-inconsistent-stackm ...