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
  1. 3 7
  1. 4
  1. 2 2
  1. 1
  1. 77 1010
  1. 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内的幂就行了
 
  1. #include <iostream>
  2. #include <cstdio>
  3. using namespace std;
  4.  
  5. const int N = ;
  6. typedef long long LL;
  7. LL l, r;
  8. LL prime[N];
  9. int tot;
  10. bool visit[N];
  11.  
  12. inline void input()
  13. {
  14. cin >> l >> r;
  15. }
  16.  
  17. inline void solve()
  18. {
  19. if(l == r && l == )
  20. {
  21. cout << "1\n";
  22. return;
  23. }
  24.  
  25. LL ans = ;
  26. if(l == ) l++, ans++;
  27. for(int i = ; i < N; i++)
  28. {
  29. if(!visit[i]) prime[++tot] = i;
  30. for(int j = ; j <= tot; j++)
  31. {
  32. if(prime[j] * i >= N) break;
  33. visit[prime[j] * i] = ;
  34. if(!(i % prime[j])) break;
  35. }
  36. }
  37.  
  38. ans += r - l + ;
  39. for(int i = ; i <= tot; i++)
  40. {
  41. LL now = ;
  42. int times = ;
  43. while(now < l) now *= prime[i], times++;
  44. while(now <= r)
  45. {
  46. if(times > && !visit[times + ]) ans--;
  47. now *= prime[i], times++;
  48. }
  49. }
  50.  
  51. cout << ans << "\n";
  52. }
  53.  
  54. int main()
  55. {
  56. ios::sync_with_stdio();
  57. input();
  58. solve();
  59. return ;
  60. }

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. python基础——多重继承

    python基础——多重继承 继承是面向对象编程的一个重要的方式,因为通过继承,子类就可以扩展父类的功能. 回忆一下Animal类层次的设计,假设我们要实现以下4种动物: Dog - 狗狗: Bat ...

  2. Makefile_:=与=的区别

    1."=" make会将整个makefile展开后,再决定变量的值.也就是说,变量的值将会是整个makefile中最后被指定的值.看例子: x = foo            y ...

  3. 413. Arithmetic Slices

    /**************************Sorry. We do not have enough accepted submissions.*********************** ...

  4. EF – 4.CRUD与事务

    5.6.1 <Entity Framework数据更新概述>  首先介绍Entity Framework实现CRUD的基本方法,接着介绍了如何使用分部类增强和调整数据实体类的功能与行为特性 ...

  5. jQueryEasyUi验证

        多重验证: { field : 'startPort', title : "起始端口", editor: "text", width : 50, edi ...

  6. jQuery - 4.简单选择器

    4.1 简单选择器   (1) :first 选取第一个元素.   (2) :last 选取最后一个元素.  (3) :not(选择器) 选取不满足"选择器"条件的元素   (4) ...

  7. 【PHP&&MySQL详解】

    PHP和MySQL是一对好搭档,PHP中有一个很大的扩展库专门针对对MySQL的操作.当然,作为一个PHP程序员,首先对MySQL的增删查改要非常熟悉才行. MySQL数据库的连接数大概在6w个左右, ...

  8. <转>FreeMarker内置函数

    一. Sequence的内置函数1. sequence?first 返回sequence的第一个值.2. sequence?last 返回sequence的最后一个值.3. sequence?reve ...

  9. HP SAN Switch光纖交換機命令行畫zone

    有時候我們無法登陸網頁交互界面去操縱交換機,如下提供了命令行方式從交換機劃zone 1.創建別名 alicreate "SummaryDB_N", "211,14; 21 ...

  10. phpcms 完美实现 导航栏当前栏目高亮

    我们在用phpcms做网站的时候,经常碰到导航栏高亮功能,或者侧栏高亮,这个会涉及到几个问题: .栏目列表页子栏目高亮判断,如果当前页面为子栏目,他的顶级栏目如果在导航栏也要高亮. .内容页高亮,这个 ...