Interesting Numbers URAL - 2070 (规律)

博客讲述Nikolay和Asya对有趣整数的不同定义,Nikolay认为质数有趣,Asya认为正除数数量为质数的整数有趣,他们称两人看法一致的整数为满足的整数。他们要研究区间[L; R]内的数,需计算该区间内满足条件的整数数量,思路是减去不符合的。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Interesting Numbers

 URAL - 2070 

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

 

思路:把不符合的减去就行了

 

#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <string>
#include <functional>
#include <cstdio>
#include <cmath>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
#define ll long long
#define F first
#define S second
#define p_b push_back
#define m_p make_pair
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int M = 1e7 + 7;
const int N = 1e6 + 100;

ll prime[N];
int isprime[N];
void getprime() {
	
	memset(prime, 0, sizeof(prime));
	int n = 1e6+20;
	for (int i = 2; i <= n; ++i) {
		if (!prime[i]) prime[++prime[0]] = i, isprime[i] = 1;
		for (int j = 1; j <= prime[0] && prime[j] <= n/i; ++j) {
			prime[prime[j]*i] = 1;
			if (i % prime[j] == 0) break;
		}
	}
	
}
ll sum(ll x) {
	
	ll not_is = 0;
	for (int i = 1; ; ++i) {
		ll y = prime[i]*prime[i];
		int num = 3;
		if (y > x) break;
		while (y <= x) {
			if (isprime[num])
				++not_is;
			y *= prime[i];
			++num;
		}
	}
	return x - not_is;
}


int main() {
	
	getprime();
	//printf ("%d\n", prime[0]);
	ll l, r;
	scanf ("%lld %lld", &l, &r);
	printf ("%lld\n", sum(r) - sum(l-1));
	
	return 0;
} 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值