2013春季SD高校ACM周赛9(SDUT) -E
来源:互联网 发布:贝佳斯原理 知乎 编辑:程序博客网 时间:2024/04/30 06:09
Fermat’s Chirstmas Theorem
Time Limit: 1000MS Memory limit: 65536K
题目描述
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.
To illustrate, each of the following primes can be expressed as the sum of two squares:
5 = 22 + 12
13 = 32 + 22
17 = 42 + 12
41 = 52 + 42
Whereas the primes 11, 19, 23, and 31 cannot be expressed as a sum of two squares. Write a program to count the number of primes that can be expressed as sum of squares within a given interval.
输入
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.
输出
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.
示例输入
10 2011 19100 1000-1 -1
示例输出
10 20 4 211 19 4 2100 1000 143 69
#include<iostream>#include<cstring>#include<cstdio>#include<ctime>#include<algorithm>using namespace std;int n=1000003; bool visit[10100000];int prime[10000000];void init_prim()//素数打表 这个比较高效 复杂度线性? {memset(visit, true, sizeof(visit));int num = 0;for (int i = 2; i <= n; ++i){if (visit[i] == true){num++;prime[num]=i;}for (int j = 1; ((j <= num) && (i * prime[j] <= n)); ++j){visit[i * prime[j]] = false;//if (i % prime[j] == 0) break; //点睛之笔}}}int main(){memset(prime, 0, sizeof(prime)); int count1;int count2;int a,b;init_prim();while(scanf("%d%d",&a,&b)){if(a==-1&&b==-1)break;count1=0;count2=0;for(int i=0;i<=100000;i++){if(prime[i]&&prime[i]>=a&&prime[i]<=b)//加上prime[i]就对~ 不加就错~ {count1++;if((prime[i]-1)%4==0) count2++; if(prime[i]==2) count2++; }}cout<<a<<" "<<b<<" "<<count1<<" "<<count2<<endl;}return 0;}
- 2013春季SD高校ACM周赛9(SDUT) -E
- 2013春季SD高校ACM周赛9(SDUT) -A
- 2013春季SD高校ACM周赛9(SDUT) -b
- 【2013春季SD高校ACM周赛8(SDUT)】各水题题解
- 2013春季SD高校ACM周赛8(SDUT)
- 2013寒假SD高校ACM周赛3(SDUT)
- 【2013寒假SD高校ACM周赛4(SDJZU & SDUT)】 超级玛丽
- 2013寒假SD高校ACM周赛3—Steps
- 【再看细节】SDUT春季高校周赛9 Problem E——A Tale from the Dark Side of The Moon
- 【读题坑爹】 2013寒假SD高校ACM周赛总结
- 【打表找规律】2013寒假SD高校ACM周赛5——I’ve Got Your Back(gammon)
- sd acm省赛(c-e
- 2013 CSDN & 西南大学 高校俱乐部 春季巡讲
- 2013 山东科技大学CSDN高校俱乐部春季巡讲
- 【差一点就坑了】SDUT春季高校周赛8(SDUT2038) Problem F——数字游戏
- 山东大学(威海)CSDN高校俱乐部2013年春季学期第一次会员大会
- 2013年天津工业大学高校俱乐部春季学期巡讲实录
- 高校ACM题库
- shell脚本调试方法
- log4j配置示例
- FTP 工具类
- PHPMailer - PHP email transport class
- 谷歌三大核心技术(一)Google File System中文版
- 2013春季SD高校ACM周赛9(SDUT) -E
- ubuntu10.04下安装windows7
- 黑马程序员——java编程那些事儿____IO流(一)
- struts2学习笔记模型驱动
- 找出100个50位数之和的前十位数字。
- POJ 1006
- PHP调用python
- 谷歌三大核心技术(二)Google MapReduce中文版
- Windows不能在本地计算机启动OracleDBConsoleorcl