zoukankan      html  css  js  c++  java
  • Codeforces 113C

    题目链接

    C. Double Happiness
    time limit per test
    5 seconds
    memory limit per test
    128 megabytes
    input
    standard input
    output
    standard output

    On the math lesson a teacher asked each pupil to come up with his own lucky numbers. As a fan of number theory Peter chose prime numbers. Bob was more original. He said that number t is his lucky number, if it can be represented as:

    t = a2 + b2, 
    where a, b are arbitrary positive integers.

    Now, the boys decided to find out how many days of the interval [l, r] (l ≤ r) are suitable for pair programming. They decided that the day i (l ≤ i ≤ r) is suitable for pair programming if and only if the number i is lucky for Peter and lucky for Bob at the same time. Help the boys to find the number of such days.

    Input

    The first line of the input contains integer numbers l, r (1 ≤ l, r ≤ 3·108).

    Output

    In the only line print the number of days on the segment [l, r], which are lucky for Peter and Bob at the same time.

    Sample test(s)
    input
    3 5
    output
    1
    input
    6 66
    output
    7
    关于bitset的使用,可以看这里
    关于高斯整数,可以点这里
    
    
     1 /*************************************************************************
     2     > File Name: 113C.cpp
     3     > Author: Stomach_ache
     4     > Mail: sudaweitong@gmail.com
     5     > Created Time: 2014年07月20日 星期日 13时34分53秒
     6     > Propose: 
     7  ************************************************************************/
     8 
     9 #include <cmath>
    10 #include <string>
    11 #include <bitset>
    12 #include <cstdio>
    13 #include <fstream>
    14 #include <cstring>
    15 #include <iostream>
    16 #include <algorithm>
    17 using namespace std;
    18 
    19 const int maxn = 1e8+1e8+1e8;
    20 bitset<maxn> p;
    21 
    22 int
    23 main(void) {
    24       int L, R;
    25       scanf("%d %d
    ", &L, &R);
    26     p.set();
    27     for (int i = 3; i*i <= R; i+=2) if (p[i]) for (int j = i*i; j <= R; j+=2*i) p[j] = false;
    28     int ans = 0;
    29     for (int i = 5; i <= R; i+=4) if (p[i] && i >= L) ans++;
    30     ans += (L <= 2 && R >= 2) ? 1 : 0;
    31     printf("%d
    ", ans);
    32 
    33     return 0;
    34 }
    
    
    
    
    
  • 相关阅读:
    【前端知识体系-JS相关】组件化和React
    【前端知识体系-JS相关】虚拟DOM和Diff算法
    【前端知识体系-JS相关】ES6专题系列总结
    【前端开发环境】前端使用GIT管理代码仓库需要掌握的几个必备技巧和知识点总结
    webpack代码分离CommonsChunkPlugin插件的使用(防止重复)
    webpack管理输出
    webpack管理资源(loader操作)
    window启动webpack打包的三种方法
    echarts地图map城市间如何连线
    echarts水球图编写
  • 原文地址:https://www.cnblogs.com/Stomach-ache/p/3856190.html
Copyright © 2011-2022 走看看