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万以下有多少个循环质数?

  1. //(Problem 35)Circular primes
  2. // Completed on Fri, 26 Jul 2013, 06:17
  3. // Language: C
  4. //
  5. // 版权所有(C)acutus (mail: acutus@126.com)
  6. // 博客地址:http://www.cnblogs.com/acutus/#include<stdio.h>
  7. #include<math.h>
  8. #include<string.h>
  9. #include<ctype.h>
  10. #include<stdlib.h>
  11. #include<stdbool.h>
  12.  
  13. bool isprim(int n)
  14. {
  15. int i=;
  16. for(; i*i<n; i++)
  17. {
  18. if(n%i==) return false;
  19. }
  20. return true;
  21. }
  22.  
  23. bool circular_prime(int n)
  24. {
  25. int i,j,flag=;
  26. char s[];
  27. int sum=;
  28. sprintf(s,"%d",n);
  29. int len=strlen(s);
  30. for(i=; i<len; i++)
  31. {
  32. if(s[i]!='' && s[i]!='' && s[i]!='' && s[i]!='')
  33. return false;
  34. }
  35. for(i=; i<len; i++)
  36. {
  37. for(j=i; j<i+len-; j++)
  38. {
  39. sum+=s[j%len]-'';
  40. sum*=;
  41. }
  42. sum+=s[j%len]-'';
  43. if(!isprim(sum)) return false;
  44. sum=;
  45. }
  46. return true;
  47. }
  48.  
  49. int main()
  50. {
  51. int sum=; //已包含2,3,5,7
  52. for(int i=; i<; i++)
  53. {
  54. if(circular_prime(i))
  55. sum++;
  56. }
  57. printf("%d\n",sum);
  58. return ;
  59. }
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. POJ 1222 EXTENDED LIGHTS OUT(高斯消元)

    [题目链接] http://poj.org/problem?id=1222 [题目大意] 给出一个6*5的矩阵,由0和1构成,要求将其全部变成0,每个格子和周围的四个格子联动,就是说,如果一个格子变了 ...

  2. Javascript数组的声明

    var cars=new Array(); cars[0]="Audi"; cars[1]="BMW"; cars[2]="Volvo"; ...

  3. 深入解读JavaScript面向对象编程实践

    面向对象编程是用抽象方式创建基于现实世界模型的一种编程模式,主要包括模块化.多态.和封装几种技术.对JavaScript而言,其核心是支持面向对象的,同时它也提供了强大灵活的基于原型的面向对象编程能力 ...

  4. activity的横屏和竖屏设置

    主要在清单文件这样配置: <application android:allowBackup="true" android:icon="@drawable/ic_la ...

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

  6. 经典阅读-《Effective C++》Item1:视C++为一个联邦语言

    C++已经是个多重范型编程语言(multiparadigm programming language),一个同时支持过程形式(procedural).面向对象形式(object-oriented).泛 ...

  7. 自定义jquery表格插件

    以前一直都是再用easyui插件来实现各种功能,但是easyui太过于庞大,使用越多对服务器负载影响越大. 基于此,在模仿easyui的dataGrid表格插件的同时,自己去封装了一个.实现了基本的j ...

  8. <转> Python的优雅技巧

    枚举 不要这么做: 全选复制放进笔记 i = 0 for item in iterable: print i, item i += 1 而是这样: 全选复制放进笔记 for i, item in en ...

  9. 关于js的一些关键知识点(call,apply,callee, caller,clourse,prototypeChain)

    可能不少学习javascript在使用call,apply,callee时会感到困惑,以下希望对于你有所帮助: 1.~~~call ,apply是函数(函数对象)的方法:callee是函数argume ...

  10. 【双模卡的相关知识】解SIM卡前需要知道的信息(SIM年分和厂商识别)

    <ignore_js_op> 二.SIM版本问题SIM卡的版本有两种说法,一是有些是制造厂制定的,二是电信公司的制定.下面以移动为例,目前我们手里的SIM有几种版本:v0.v1.v2.v3 ...