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. java程序错误类型及异常处理

    一.程序的错误类型 在程序设计中,无论规模是大是小,错误总是难免的.程序的设计很少有能够一次完成,没有错误的(不是指HelloWorld这样的程序,而是要实现一定的功能,具备一定实用价值的程序),在编 ...

  3. iOS开发获取缓存文件的大小并清除缓存

    移动应用在处理网络资源时,一般都会做离线缓存处理,其中以图片缓存最为典型,其中很流行的离线缓存框架为SDWebImage. 但是,离线缓存会占用手机存储空间,所以缓存清理功能基本成为资讯.购物.阅读类 ...

  4. 如何打开Nib文件

    作者:ani_di  版权所有,转载务必保留此链接 http://blog.csdn.net/ani_di # 如何打开Nib文件 有段时间没有灌水,今天分享一个小技巧. nib文件是Cocoa Ap ...

  5. iOS设计模式——MVC(Model-View-Controller)

    Modol View Controller(MVC)是一种最早的也是最成功的可重用的设计模式,70年代的时候首次在smaltalk编写的程序中成功使用.基于MVC设计 模式,Cocoa整体架构可以划分 ...

  6. 搭建Myeclipse下Java Web开发环境

    1.准备 先下载软件:Myeclipse:http://www.xiazaiba.com/html/23858.html tomcat:http://files.cnblogs.com/files/l ...

  7. C++ 变量的声明与定义的区别

    变量声明和定义的区别 我们在程序设计中,时时刻刻都用到变量的定义和变量的声明,可有些时候我们对这个概念不是很清楚,知道它是怎么用,但却不知是怎么一会事,下面我就简单的把他们的区别介绍如下:(望我的指点 ...

  8. Lucence.net索引技术 一

    1.建立索引 为了对文档进行索引,Lucene 提供了五个基础的类,他们分别是 Document, Field, IndexWriter, Analyzer, Directory.下面我们分别介绍一下 ...

  9. 关于php支持的协议与封装协议

    <?php /* * php://stdin 标准输入流 * php://stdout 标准输入流 * php://stderr 标准错误流 * php://output 只写的数据流 * ph ...

  10. tornado模板的自动编码问题(autoescape )

    tornado新版(具体版本未知)支持自动转义,比如{{ "<div>" }}不会输出html标签,而是进行转义. {{ module.test(10) }} 也会进行 ...