Interesting Numbers URAL - 2070 (规律)

编程入门 行业动态 更新时间:2024-10-25 10:28:48

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;
} 

 

更多推荐

Interesting Numbers URAL - 2070 (规律)

本文发布于:2023-06-13 23:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1415635.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:规律   Numbers   Interesting   URAL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!