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. zmq-ios framwork

    1.附件见zeromq-ios.framework百度网盘/iOS/zmq 2.zeromq-ios.framework解压拖进工程文件 3.objc-zmq见百度网盘/iOS/zmq 4.objc- ...

  2. java Unicode、ISO-8859-1、GBK、UTF-8编码转换深入浅出

    参考文献:搞懂ASCII, ISO8859-1, ANSI和Unicode Unicode百度文献 ISO-8859-1百度文献 注: 1.utf-8虽然是国际编码,对不同范围的字符使用不同长度的编码 ...

  3. android app 内部文件路径

    public class MainActivity extends Activity { final String FILE_NAME = "crazyit.bin"; @Over ...

  4. php 分页

    分页类 <?php /** file: page.class.php 完美分页类 Page */ class Page { private $total; //数据表中总记录数 private ...

  5. samba 报错

    [root@GitLab data_nfs]# smbclient //localhost/public WARNING: The security=share option is deprecate ...

  6. C#的反射机制

    using System; using System.Collections; using System.Collections.Generic; using System.IO; using Sys ...

  7. Delphi中的函数指针判断是否为空

    delphi函数指针 只有@@p才代表了函数指针本身的地址   assigned(p) 判断是否为空 或者用 @p=nil 来判断函数指针是不是为空 Delphi中的函数指针实际上就是指针,只是在使用 ...

  8. 谈谈Delph中的类和对象2---类可以理解成一种特殊的数据结构、类型转换

    三.类可以理解成一种特殊的数据结构 我们知道数据类型可以进行强制类型转换,类既然可以理解成一种数据类型,那么它也应该可以进行类型转换.比如下面代码为一个按钮(Button1)的单击事件 procedu ...

  9. JavaScript是如何实现继承的(六种方式)

    大多OO语言都支持两种继承方式: 接口继承和实现继承 ,而ECMAScript中无法实现接口继承,ECMAScript只支持实现继承,而且其实现继承主要是依靠原型链来实现,下文给大家技术js实现继承的 ...

  10. Tkprof工具详解一

      注明:一些文章是从别人的博客中转载过来的,方便自己以后查阅:在数据库生成的oracle trace文件中,可读性是比较差的,此时可使用tkprof工具来格式化trace文件,tkprof是一个命令 ...