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. C#中的里氏替换原则

    里氏转换原则 子类可以赋值给父类对象 父类对象可以强制转化为对应的子类对象 里氏替换原则直观理解就是"子类是父类",反过来就说不通了. 就像男人是人对的,但人是男人就不对了. 这样 ...

  2. Theme.AppCompat.Light无法找到问题

    使用adt开发新建一个Android app.选择支持的SDK版本号假设小于11(Android3.0)就会报例如以下错误. error: Error retrieving parent for it ...

  3. centos7 改变终端背景色

    首先打开终端 2:选择 edit->preferences->profile 3: "model1"是我自己改的名字,最开始是"unname".双击 ...

  4. java.lang.NoClassDefFoundError: ch/qos/logback/core/joran/spi/JoranException

    问题描述:启动tomcat服务器的时候,报找不到JoranException类的异常 原因:tomcat中没有logback-core-1.1.2.jar包 解决方法:在tomcat中的lib目录添加 ...

  5. CSDN开源夏令营 基于Compiz的switcher插件设计与实现之前期准备 git的简单使用

    因为项目的代码须要上传到git上.就须要学习一下git的使用了. 我初步接触了一下git,准备用此帖来记录git的学习,此帖会随着我对git了解的深入动态更新. 一.GIT的介绍 1.概述:git是一 ...

  6. Weblogic配置故障转移

    前提:实现负载均衡,即当访问项目时,会通过代理服务器将请求分发到不同的服务器上. weblogic的故障转移配置 在项目的WEB-INF目录下创建weblogic.xml <!DOCTYPE w ...

  7. python3读取HDA零售企业数据(一)

    #-*- coding:utf-8 -*- # 下载河南FDA各药品经营企业目录 import urllib.request import urllib.parse import re import ...

  8. web 开发之js---HTML5之广播聊天室

    那个头标题很有意思js做的 http://www.cnblogs.com/xgao/p/4200985.html

  9. Zxing二维码解析——图文转换

    一:文字转化为二维码图片. package com.xhm.tool; import java.util.Hashtable; import android.graphics.Bitmap; impo ...

  10. Ant自己主动编译打包&amp;公布 android项目

    Eclipse用起来尽管方便,可是编译打包android项目还是比較慢,尤其将应用打包公布到各个渠道时,用Eclipse手动打包各种渠道包就有点不切实际了,这时候我们用到Ant帮我们自己主动编译打包了 ...