zoukankan      html  css  js  c++  java
  • URAL 2070 Interesting Numbers

    Discription
    Nikolay and Asya investigate integers together in their spare time. Nikolay thinks an integer is interesting if it is a prime number. However, Asya thinks an integer is interesting if the amount of its positive divisors is a prime number (e.g., number 1 has one divisor and number 10 has four divisors).
    Nikolay and Asya are happy when their tastes about some integer are common. On the other hand, they are really upset when their tastes differ. They call an integer satisfying if they both consider or do not consider this integer to be interesting. Nikolay and Asya are going to investigate numbers from segment [ LR] this weekend. So they ask you to calculate the number of satisfying integers from this segment.

    Input

    In the only line there are two integers L and R (2 ≤ L ≤ R ≤ 10 12).

    Output

    In the only line output one integer — the number of satisfying integers from segment [ LR].

    Example

    inputoutput
    3 7
    
    4
    
    2 2
    
    1
    
    77 1010
    
    924

        尝试用区间内总数减去不满足条件的数个数来得到答案。

        不满足的数有两种:是质数但是约数个数不是质数,不是质数但是约数个数是质数。

        第一种情况不存在,而第二种情况又得满足它是某个质数的若干次方,所以这就是一个水题了23333

    #include<bits/stdc++.h>
    #define ll long long
    using namespace std;
    const int maxn=1000000;
    int zs[maxn/5],t=0;
    bool v[maxn+5];
    ll L,R;
    
    inline void init(){
    	v[1]=1;
    	for(int i=2;i<=maxn;i++){
    		if(!v[i]) zs[++t]=i;
    		for(int j=1,u;j<=t&&(u=zs[j]*i)<=maxn;j++){
    			v[u]=1;
    			if(!(i%zs[j])) break;
    		}
    	}
    }
    
    inline ll solve(ll x){
    	ll ans=0;
    	
    	for(int i=2;i*(ll)i<=x;i++) if(!v[i])
    		for(ll j=i*(ll)i,u=2;j<=x;j=j*(ll)i,u++) if(!v[u+1]) ans++;
    	
    	return x-ans;
    } 
    
    int main(){
    	init();
    	cin>>L>>R;
    	printf("%lld
    ",solve(R)-solve(L-1));
    	return 0;
    }
    

      

  • 相关阅读:
    ActiveMQ( 一) 同步,异步,阻塞 JMS 消息模型
    rocketmq (一)运行原理以及使用问题
    Springboot+ActiveMQ(ActiveMQ消息持久化,保证JMS的可靠性,消费者幂等性)
    ActiveMQ(下载,启动,java程序中 如何操作)
    ActiveMQ(为什么要使用消息中间件,JMS传输模型)
    java(线程池的创建方式,和线程池的原理)
    java多线程
    Zookeeper实现负载均衡
    Zookeeper实现分布式锁
    SpringCloud-断路器(Hystrix)
  • 原文地址:https://www.cnblogs.com/JYYHH/p/8683655.html
Copyright © 2011-2022 走看看