国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設(shè)計 > 正文

Ural 2070 Interesting Numbers

2019-11-08 03:13:33
字體:
供稿:網(wǎng)友

Description

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 [L, R] 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 [L, R].

題意

Nikolay 認為一個數(shù)是有趣的,若這個數(shù)是素數(shù);Asya 認為一個數(shù)是有趣的,當一個數(shù)的約數(shù)個數(shù)為 k ,且 k 是一個素數(shù)。

問在區(qū)間 [L,R] 中,兩人同時覺得有趣或同時覺得不有趣的數(shù)的個數(shù)。

分析

首先,當一個數(shù)是素數(shù)的時候,這個數(shù)的約數(shù)個數(shù)為 2 (1 和自身),是素數(shù);即兩人必然同時認為一個素數(shù)是有趣的。

之后,考慮合數(shù)的情況。一個數(shù)約數(shù)的個數(shù)可以通過公式快速求得(套質(zhì)因數(shù)分解的板): n→divisorNum=ab11×ab22×…×abtottot=(b1+1)×(b2+1)×...×(btot+1) 很容易看到,當一個合數(shù)的因子數(shù) >=2 時,這個數(shù)的約數(shù)個數(shù)必然是一個合數(shù),則兩人同時認為這個數(shù)不有趣。

因此,只需要判斷一個素數(shù)的任意冪次,當 n=ab ,且 b+1 是一個素數(shù)的時候,兩人的判斷是不同的,將這部分數(shù)去除即可得到正確答案。

故預處理出 [1,106] 區(qū)間中的素數(shù),并以其為底,不斷獲取不同冪次的值,同時判斷 b+1 是否為素數(shù)。

HINT:由于最大右區(qū)間為 1012 ,任意大于 106 的數(shù)的平方即大于 1012 ,故不需要打更大的素數(shù)表。

代碼

#include<bits/stdc++.h>using namespace std;const long long inf = 1e12;const int N = 1000001;bool isprime[N];int primes[N/3], tot;void getPrime() { tot = 0; memset(isprime, 0, sizeof(isprime)); for(int i=2, j;i<N;i++) { if(!isprime[i]) primes[tot++] = i; for(j=0;j<tot && i*primes[j] < N;++j) { isprime[i*primes[j]] = true; if(i % primes[j] == 0) break; } }}int main(){ long long j, l, r; getPrime(); vector<long long> vec; for(int i=0, x;i<tot;i++) for(j=(long long)primes[i]*primes[i], x=2;j<=inf;j*=primes[i], ++x) if(!isprime[x+1]) vec.push_back(j); sort(vec.begin(), vec.end()); scanf("%I64d %I64d",&l,&r); int lidx = lower_bound(vec.begin(), vec.end(), l) - vec.begin(); int ridx = upper_bound(vec.begin(), vec.end(), r) - vec.begin(); printf("%I64d/n", r-l+1-(ridx-lidx));}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 武义县| 浦江县| 芒康县| 湖南省| 孟村| 汝南县| 湘乡市| 社旗县| 龙南县| 黄梅县| 抚顺县| 丽江市| 长丰县| 平南县| 宁强县| 临夏市| 色达县| 汪清县| 泗洪县| 乌海市| 伊宁县| 印江| 久治县| 从化市| 喀喇| 平和县| 临武县| 闵行区| 临夏市| 潞城市| 鹰潭市| 上饶市| 六枝特区| 峡江县| 余姚市| 黔西| 聂拉木县| 科技| 清远市| 新河县| 双流县|