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. openStack juno for ubuntu12-04

    <一,preinstall basic conf,pre Env> 1,pwgen(openssl rand -hex 10) some Open-Stack services add a ...

  2. java 循环制作三角形

    package hello; public class Sanjiao { public static void main(String[]args){ for(int i=1;i<5;i++) ...

  3. Docker之dockerfile

    一.什么是dockerfile Docker通过对于在dockerfile中的一系列指令的顺序解析实现自动的Image的构建: 通过使用build命令,根据dockerfile的描述来构建镜像: bu ...

  4. ADO.NET详解----核心对象的使用

    一.Connection对象 指定某个具体数据源以及提供登陆方式及用户名与密码. Connection对象的主要成员: 1.ConnectionString属性:连接字符串,指定要操作的数据库以及登录 ...

  5. eclipse:Tomcat设置jvm,解决java.lang.OutOfMemoryError: Java heap space 堆内存溢出

    eclipse 有启动参数里设置jvm大小,因为eclipse运行时自己也需要jvm,所以eclipse.ini里设置的jvm大小不是具体某个程序运行时所用jvm的大小,这和具体程序运行的jvm大小无 ...

  6. JS 获取浏览器窗口大小clientWidth、offsetWidth、scrollWidth

    常用: JS 获取浏览器窗口大小   // 获取窗口宽度 if (windows.innerWidth) winWidth = windows.innerWidth; else if ((docume ...

  7. winform代码:关联窗体数据更新,删除dataGridview中选中的一行或多行

    一.关联窗体数据更新 关联窗体数据修改时,如果一个为总体数据显示窗体A,另一个为详细修改窗体B,从A进入B,在B中对数据进行修改,然后返回A,这时A窗体的数据需要更新. 我采用最简单的方法,首先保证每 ...

  8. [LeetCode]题解(python):070-Climbing Stairs

    题目来源: https://leetcode.com/problems/climbing-stairs/ 题意分析: 爬楼梯,一次可以爬一步或者两步.如果要爬n层,问一共有多少种爬法.比如说,如果是3 ...

  9. 大数据情报分析公司Palantir

    最近在学习图数据计算方面技术,在寻找现实应用时发现美国Palantir公司已将所谓的多源异构数据融合分析技术运用的炉火纯青.Palantir创立于2004年,最早是因PayPal公司为保障支付安全而逐 ...

  10. LintCode-编辑距离

    题目描述: 给出两个单词word1和word2,计算出将word1 转换为word2的最少操作次数. 你总共三种操作方法: 插入一个字符 删除一个字符 替换一个字符 样例 给出 work1=" ...