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. windows 配置squid反向代理服务器

    发现Window版本的Squid 和 Linux 配置有点不一样 一.配置squid\etc目录1.squid.conf.default 拷贝一份重新命名为squid.conf2.cachemgr.c ...

  2. Mongodb 的学习

    传送门: # 官方网站 及 下载地址 https://www.mongodb.com/download-center/enterprise/releases # 之前简单学习的笔记http://www ...

  3. root 执行过程权限问题

    mysql 1449 : The user specified as a definer ('root'@'%') does not exist 解决方法 权限问题,授权 给 root  所有sql ...

  4. Cannot open channel to 3 at election address :3888 java.net.ConnectException: Connection refused (Connection refused)

    关于Linux中搭建分布式时可能遇到的问题 这个问题来自于今天安装zookeeper时踩的一个大坑,害的我花了一天时间.在搭建zookeeper的分布式时,往往要进行这样的配置: server.1=h ...

  5. 解决:Adb connection Error:远程主机强迫关闭了一个现有的连接

    最近刚入手了一台G12,用它来调试程序的时候,eclipse的console总是出现如下的错误“Adb connection Error:远程主机强迫关闭了一个现有的连接” 问题出现的原因:这是ddm ...

  6. django学习总结

    tips:django官方中文文档(http://python.usyiyi.cn/django/index.html),django基础教程(http://www.ziqiangxuetang.co ...

  7. /bin/sh^M:bad interpreter: No such file or directory

    bash脚本:/bin/sh^M:bad interpreter: No such file or directory   dos2unix 实际上就是把文本文件中面的^M删除 用SHELL 写了一个 ...

  8. mysql windows安装

    http://blog.csdn.net/tossgoon/article/details/44412491 1.从该地址http://dev.mysql.com/downloads/mysql/中选 ...

  9. JVM调优- jstat(转)

    jstat的用法 用以判断JVM是否存在内存问题呢?如何判断JVM垃圾回收是否正常?一般的top指令基本上满足不了这样的需求,因为它主要监控的是总体的系统资源,很难定位到java应用程序. Jstat ...

  10. mysql主从实验

    实验一: 服务器A与服务器B是主从关系,关联的库有test1,.test2库,主从一直运行正常,此时由于业务的需求,需再增加test3库,并让其仍然维持主从关系,应该怎么做? 步骤一: 修改从库服务器 ...