2070. Interesting Numbers

Time limit: 2.0 second
Memory limit: 64 MB
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 ≤ 1012).

Output

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

Samples

input output
3 7
4
2 2
1
77 1010
924
Problem Author: Alexey Danilyuk
Problem Source: Ural Regional School Programming Contest 2015
Difficulty: 221
 
题意:问l~r之间
1、x是个质数
2、约数个数是质数
要么满足两者,要么两者都不满足的数的个数
 
分析:
我们只要扣除只满足一个的数就可以了
首先1特殊处理
 
 
考虑x=p1^k1 * p2^k2 *....
当质因子超过1个,则两者都不满足
当质因子只有一个,当k==1时,两者满足
当k>1时,就要扣除
所以只用枚举质数,查看在l-r内的幂就行了
 
 #include <iostream>
#include <cstdio>
using namespace std; const int N = ;
typedef long long LL;
LL l, r;
LL prime[N];
int tot;
bool visit[N]; inline void input()
{
cin >> l >> r;
} inline void solve()
{
if(l == r && l == )
{
cout << "1\n";
return;
} LL ans = ;
if(l == ) l++, ans++;
for(int i = ; i < N; i++)
{
if(!visit[i]) prime[++tot] = i;
for(int j = ; j <= tot; j++)
{
if(prime[j] * i >= N) break;
visit[prime[j] * i] = ;
if(!(i % prime[j])) break;
}
} ans += r - l + ;
for(int i = ; i <= tot; i++)
{
LL now = ;
int times = ;
while(now < l) now *= prime[i], times++;
while(now <= r)
{
if(times > && !visit[times + ]) ans--;
now *= prime[i], times++;
}
} cout << ans << "\n";
} int main()
{
ios::sync_with_stdio();
input();
solve();
return ;
}

ural 2070. Interesting Numbers的更多相关文章

  1. URAL 2070 Interesting Numbers (找规律)

    题意:在[L, R]之间求:x是个素数,因子个数是素数,同时满足两个条件,或者同时不满足两个条件的数的个数. 析:很明显所有的素数,因数都是2,是素数,所以我们只要算不是素数但因子是素数的数目就好,然 ...

  2. 【线性筛】【筛法求素数】【约数个数定理】URAL - 2070 - Interesting Numbers

    素数必然符合题意. 对于合数,如若它是某个素数x的k次方(k为某个素数y减去1),一定不符合题意.只需找出这些数. 由约数个数定理,其他合数一定符合题意. 就从小到大枚举素数,然后把它的素数-1次方都 ...

  3. 递推DP URAL 1586 Threeprime Numbers

    题目传送门 /* 题意:n位数字,任意连续的三位数字组成的数字是素数,这样的n位数有多少个 最优子结构:考虑3位数的数字,可以枚举出来,第4位是和第3位,第2位组成的数字判断是否是素数 所以,dp[i ...

  4. 递推DP URAL 1009 K-based Numbers

    题目传送门 题意:n位数,k进制,求个数分析:dp[i][j] 表示i位数,当前数字为j的个数:若j==0,不加dp[i-1][0]; 代码1: #include <cstdio> #in ...

  5. 算法笔记_093:蓝桥杯练习 Problem S4: Interesting Numbers 加强版(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 Problem Description We call a number interesting, if and only if: 1. Its d ...

  6. java实现 蓝桥杯 算法提高 Problem S4: Interesting Numbers 加强版

    1 问题描述 Problem Description We call a number interesting, if and only if: 1. Its digits consists of o ...

  7. Ural 2070:Interesting Numbers(思维)

    http://acm.timus.ru/problem.aspx?space=1&num=2070 题意:A认为如果某个数为质数的话,该数字是有趣的.B认为如果某个数它分解得到的因子数目是素数 ...

  8. URAL 2031. Overturned Numbers (枚举)

    2031. Overturned Numbers Time limit: 1.0 second Memory limit: 64 MB Little Pierre was surfing the In ...

  9. ural 1150. Page Numbers

    1150. Page Numbers Time limit: 1.0 secondMemory limit: 64 MB John Smith has decided to number the pa ...

随机推荐

  1. C 替换字符方法--1

    #include "stdafx.h" //linux 底下要去掉这一行 #include <stdio.h> #include<stdlib.h> #in ...

  2. poj1703(各种姿势)

    题目链接:http://poj.org/problem?id=1703 题意:有n个人分别属于两个团伙,接下来m组形如 ch, x, y的数据,ch为"D"表示 x, y属于不同的 ...

  3. 1 mysql的安装

    win10 总之前期的步骤大概有:1下载安装:2 安装好后配置环境变量:3:登陆数据库 1:安装 mysql有安装版和直接解压就可以用的,据说大神都是安装的直接解压的,但鉴于自己是小白,就整了个安装版 ...

  4. PHP魔术方法在框架中的应用

    class usermodel{ protected $email='user@163.com'; protected $data=array(); public function __set($k, ...

  5. sqlserver 用户、账号、安全等问题小汇

    一.孤立账号 SQL Server 的用户安全管理分两层,整个SQL Server 服务器一层,每个数据库一层. 在服务器层的帐号,叫登录账户(SQL Server:服务器角色),可以设置它管理整个S ...

  6. Delphi中函数定义和声明的位置

    当函数(或过程)A定义在函数(或过程)B之前,那么函数B就可以调用函数A,并且编译成功,例如下面的 procedure TForm1.btn1Click(Sender: TObject); 和   f ...

  7. Delphi面向对象的可见性表示符

    Delphi能通过在声明域和方法的时候用protected.private.public.published和automated指示符来对对象提供进一步的控制.使用这些关键字的语法如下 TSomeOb ...

  8. <转>SQL语句执行顺序说明

    原文地址:http://www.cnblogs.com/summer_adai/archive/2011/10/28/2227605.html SQL 不同于与其他编程语言的最明显特征是处理代码的顺序 ...

  9. hibernate base

    第一个类:Person.java package org.crazyit.app.domain; import java.io.Serializable;import java.util.ArrayL ...

  10. Http 请求处理流程

    引言 我查阅过不少Asp.Net的书籍,发现大多数作者都是站在一个比较高的层次上讲解Asp.Net.他们耐心.细致地告诉你如何一步步拖放控件.设置控件属性.编写CodeBehind代码,以实现某个特定 ...