zoukankan      html  css  js  c++  java
  • URAL 2070 Interesting Numbers (找规律)

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <cctype>
    #include <cmath>
    #include <stack>
    #define frer freopen("in.txt", "r", stdin)
    #define frew freopen("out.txt", "w", stdout)
    using namespace std;
    
    typedef long long LL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const double inf = 0x3f3f3f3f3f3f;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int maxn = 1e6 + 5;
    const int mod = 1e8;
    const char *mark = "+-*";
    const int dr[] = {-1, 0, 1, 0};
    const int dc[] = {0, 1, 0, -1};
    int n, m;
    const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    inline int Min(int a, int b){ return a < b ? a : b; }
    inline int Max(int a, int b){ return a > b ? a : b; }
    inline LL Min(LL a, LL b){ return a < b ? a : b; }
    inline LL Max(LL a, LL b){ return a > b ? a : b; }
    inline bool is_in(int r, int c){
        return r >= 0 && r < n && c >= 0 && c < m;
    }
    int a[maxn];
    vector<int> prime;
    
    int main(){
        for(int i = 2; i <= sqrt(1000001+0.5); ++i) if(!a[i]){
            for(int j = i * i; j <= 1000001; j += i) a[j] = 1;
        }
        for(int i = 2; i <= 1000001; ++i) if(!a[i])  prime.push_back(i);
        LL x, y;
        while(cin >> x >> y){
            int cnt = 0;
            for(int i = 0; i < prime.size(); ++i){
                LL t = (LL)prime[i] * (LL)prime[i];
                int k = 2;
                while(t <= y){
                    ++k;
                    if(!a[k] && t >= x && t <= y)  ++cnt;
                    t *= prime[i];
                }
            }
    
            LL ans = y - x - cnt + 1;
            cout << ans << endl;
        }
        return 0;
    }
    

      

  • 相关阅读:
    问题总结
    Https网络安全架构设计
    分布式ID生成策略
    [转]匿名内部类详解
    JAVA名词解释
    MQ实战
    手写SpringMVC实现
    多线程问答
    BIO、NIO实战
    spring中@Value("${key}")值原样输出${key}分析与解决
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5796882.html
Copyright © 2011-2022 走看看