(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 ...
随机推荐
- HelloX项目github协同开发指南
概述 为了提高协同开发效率,HelloX项目已托管到github网站上.根据目前的开发进展,创建了下列几个子项目: HelloX操作系统内核项目:https://github.com/hellox-p ...
- 【C++算法设计】八数码问题
八数码问题 [题意] 编好为1~8的8个正方形滑块摆成3行3列(一个格子为空),如图所示 每次可以移动空格相邻的滑块到空格,要计算出能移动出目标局面的最小步数,如无法达到则输出-1. [分析] 我们可 ...
- linux杂谈(十七):iscsi存储分离技术
1.iscsi简单介绍 iSCSI利用了TCP/IP的port 860 和 3260 作为沟通的渠道.透过两部计算机之间利用iSCSI的协议来交换SCSI命令,让计算机能够透过快速的局域网集线来 ...
- Android应用开发基础篇(2)-----Notification(状态栏通知)
一.概述 Notification这个部件的功能是在状态栏里显示消息提醒,比如有未读的短信或者是未接的电话,那么状态栏里都会有显示,更或者是从某个应用(比如QQ,酷我音乐等等)里按Home键 ...
- div中央
.histroyMsgSearch{ background:#Fff; text-align: center; } CSS 怎样使DIV层水平居中 今天用CSS碰到个非常棘手的问题,DIV本身未定义 ...
- !!!易控INSPEC组态软件开发小结——-一次工程文件损坏和处理经过
从加入红橡开始熟悉和使用易控(INSPEC)组态软件,值得赞扬的是INSPEC的开放性和对C#语言的支持,除此之外,便也没有感觉它与其他组态软件有太多优势,有人说INSPEC软件授权比国内其他同类的组 ...
- OpenCV 开发环境环境搭建(win10+vs2015+opencv 3.0)
OpenCV 3.0 for windows(下载地址:http://opencv.org/): 本测试中,OpenCV安装目录:D:\Program Files\opencv,笔者操作系统为64位. ...
- handlebar.js使用
官方网站:http://handlebarsjs.com/ 下载及查看使用帮助,或者用百度cdn引用 一.定义模板 <script id="entry-template" t ...
- loaded some nib but the view outlet was not set
链接地址:http://www.cnblogs.com/TivonStone/archive/2012/04/20/2460116.html 当使用 initWithNibName 函数, 并使用 由 ...
- c# 迭代器 与 集合 IEnumerable.GetEnumerator 方法
示例来源 :msdn 参考:https://msdn.microsoft.com/zh-cn/library/dscyy5s0(v=vs.110).aspx 使用匿名方法.迭代器和部分选件类创建简洁的 ...