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;
}

最新文章

  1. 【CSS】创建布局
  2. 在openwrt装ipk包
  3. 使用Gradle运行集成测试
  4. javascript中部分不能使用call apply调用来重写的构造函数
  5. sql server 2005中IMAGE类型的BUG问题
  6. td里的内容宽度自适应 及 鼠标放上显示标题div title
  7. display属性及inline-block值(可用来布局)
  8. 【Beta阶段】第三次scrum meeting
  9. SYSTEM_INFO
  10. ASP.NET Core中使用GraphQL - 第四章 GraphiQL
  11. Web前端-Ajax基础技术(上)
  12. 微信公众平台测试号 “微信登录失败,redirect_uri域名与后台配置不一致,错误代码10003”
  13. JPasswordField密码框,JList列表框
  14. cc.Mask. 纯代码拉伸遮罩
  15. 使用Visual Studio Team Services敏捷规划和项目组合管理(五)——组合管理
  16. Static需谨慎
  17. Overture 5入门之如何设置延音线
  18. Identity Server4学习系列二之令牌(Token)的概念
  19. SDN竞赛思考总结
  20. SPSS-相关性和回归分析(一元线性方程)案例解析

热门文章

  1. Linux下画原理图和PCB
  2. ueditor的上传存储问题
  3. linux系统下实时监控进程以及定位杀死挂起的进程
  4. 【POJ 2400】 Supervisor, Supervisee(KM求最小权匹配)
  5. Python内置函数之str()
  6. 实现Nullable 可空类型
  7. cxf + spring + maven 开发webservice
  8. find 多文件查找需要单引号
  9. Centos命令行报bash:.....:command not found的解决办法
  10. thinkPHP5.0的学习研究【架构】