Fermat’s Chirstmas Theorem

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

Description

In a letter dated December 25, 1640; the great mathematician Pierre de Fermat wrote to Marin Mersenne that he just proved that an odd prime p is expressible as p = a2 + b2 if and only if p is expressible as p = 4c + 1. As usual, Fermat didn’t include the proof, and as far as we know, never

wrote it down. It wasn’t until 100 years later that no one other than Euler proved this theorem.

Input

Your program will be tested on one or more test cases. Each test case is specified on a separate input line that specifies two integers L, U where L ≤ U < 1, 000, 000

The last line of the input file includes a dummy test case with both L = U = −1.

Output

L U x y

where L and U are as specified in the input. x is the total number of primes within the interval [L, U ] (inclusive,) and y is the total number of primes (also within [L, U ]) that can be expressed as a sum of squares.

Sample Input

10 20
11 19
100 1000
-1 -1

Sample Output

10 20 4 2
11 19 4 2
100 1000 143 69
#include<stdio.h>
#include<string.h> #define N 1000005 int prime[100005];
int flag[1000005];
int e; void getP() // 素数打表,找出素数存栈
{
int i, j;
e = 0;
memset(flag, 0, sizeof(flag) ); //标记初始化 for ( i=2; i<N; i++)
{
if ( flag[i]==0 )
{
prime[e++] = i; //进栈
}
for ( j=0; j<e && i*prime[j]<N; j++ )
{
flag[ i * prime[j] ] = 1;
}
}
} int main()
{
int l,u,x,y; getP();
int i;
while(scanf("%d %d",&l,&u))
{ if(l==-1 && u==-1)
break;
x=0;
y=0;
for( i=0; i<e; i++)
{
if(prime[i]>=l && prime[i]<=u )
{
x++;
if(prime[i]%4==1)
{
y++;
}
}
if(prime[i]>u)
break;
}
if(l<=2 && u>=2)
{
y++;
}
printf("%d %d %d %d\n",l, u, x, y );
}
return 0;
}

Fermat’s Chirstmas Theorem (素数打表的)的更多相关文章

  1. SDUT Fermat’s Chirstmas Theorem(素数筛)

    Fermat's Chirstmas Theorem Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描写叙述 In a letter ...

  2. hdu 5104 素数打表水题

    http://acm.hdu.edu.cn/showproblem.php?pid=5104 找元组数量,满足p1<=p2<=p3且p1+p2+p3=n且都是素数 不用素数打表都能过,数据 ...

  3. HDU 1397 Goldbach's Conjecture【素数打表】

    题意:给出n,问满足a+b=n且a,b都为素数的有多少对 将素数打表,再枚举 #include<iostream> #include<cstdio> #include<c ...

  4. Codeforces Round #315 (Div. 2C) 568A Primes or Palindromes? 素数打表+暴力

    题目:Click here 题意:π(n)表示不大于n的素数个数,rub(n)表示不大于n的回文数个数,求最大n,满足π(n) ≤ A·rub(n).A=p/q; 分析:由于这个题A是给定范围的,所以 ...

  5. CodeForces 385C Bear and Prime Numbers 素数打表

    第一眼看这道题目的时候觉得可能会很难也看不太懂,但是看了给出的Hint之后思路就十分清晰了 Consider the first sample. Overall, the first sample h ...

  6. LightOJ 1259 Goldbach`s Conjecture 素数打表

    题目大意:求讲一个整数n分解为两个素数的方案数. 题目思路:素数打表,后遍历 1-n/2,寻找方案数,需要注意的是:C/C++中 bool类型占用一个字节,int类型占用4个字节,在素数打表中采用bo ...

  7. [ACM] POJ 2635 The Embarrassed Cryptographer (同余定理,素数打表)

    The Embarrassed Cryptographer Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11978   A ...

  8. Aladdin and the Flying Carpet LightOJ - 1341 (素数打表 + 算术基本定理)

    题意: 就是求a的因数中大于b的有几对 解析: 先把素数打表 运用算术基本定理 求出a的所有因数的个数 然后减去小于b的因数的个数 代码如下: #include <iostream> #i ...

  9. Goldbach`s Conjecture LightOJ - 1259 (素数打表 哥德巴赫猜想)

    题意: 就是哥德巴赫猜想...任意一个偶数 都可以分解成两个(就是一对啦)质数的加和 输入一个偶数求有几对.. 解析: 首先! 素数打表..因为 质数 + 质数 = 偶数 所以 偶数 - 质数 = 质 ...

随机推荐

  1. java中不能用小数点(.)来做分隔符

    split()括号里是一个String的参数,所以一定要符合这种:split(".")形式,即点'.'要用双引号""括起来"."在java中 ...

  2. 利用Bootstrap简单实现一个文件上传进度条

    © 版权声明:本文为博主原创文章,转载请注明出处 说明: 1. 使用commons-fileupload.jar实现文件上传及进度监听 2. 使用bootstrap的进度条进行页面显示 3. 因为进度 ...

  3. Android服务类Service具体解析

    Service有什么作用? 很多人不明确service是用来干嘛的.事实上Service作为Android四大组件之中的一个,能够理解为一个执行在后台的Activity.它适用于处理一些不干扰用户的长 ...

  4. win7上python+theano+keras安装

    https://blog.csdn.net/yongjiankuang/article/details/50485610 其实过程很简单,首先说一下安装条件: 1.win7 (32和64都可以,下载安 ...

  5. linux修改root管理员密码

    以root 身份登录(SSH操作) 输入 passwd 命令 就可以看到提示输入新密码了 输入密码的时候是看不到字符的.

  6. 题目3 : Fibonacci

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Given a sequence {an}, how many non-empty sub-sequence of it ...

  7. centos7设置ip

    centos7不能再通过setup命令来设置ip了,但可以通过修改网卡配置文件来设置ip 在/etc/sysconfig/network-scripts目录下找到网卡配置文件,修改之前内容如下 TYP ...

  8. NPTL LinuxThreads

    Linux 线程模型的比较:LinuxThreads 和 NPTL 进行移植的开发人员需要了解的关键区别摘要 Vikram Shukla 2006 年 8 月 28 日发布 WeiboGoogle+用 ...

  9. VMWare Workstation和VMWare vSphere(转)

    VMware workstation一定是安装在window操作系统上的. VMware vSphere可以直接安装在x86机器上,使这台机器完全虚拟化. VMware vSphere主要是企业级用户 ...

  10. 动态创建Lambda表达式实现高级查询

    需求简介 最近这几天做的东西总算是回归咱的老本行了,给投资管理项目做一个台账的东西,就是类似我们的报表.其 中有一个功能是一个高级查询的需求,在查询条件方面大概有7.8个查询条件.需求就是如果一个条件 ...