求条
查看原帖
求条
1058410
Gcc_Gdb_7_8_1楼主2025/2/7 21:54
#include <bits/stdc++.h>
#ifndef __DEBUG_LIB
#define __DEBUG_LIB

bool isdebug = false;

#define change(x) isdebug = x
#define Debugc if(isdebug) cout
#define Debug if(isdebug)

#endif
using namespace std;

#define LL long long
#define Pii pair<int, int>
#define ULL unsigned long long

namespace gdb7
{
	int a[1000010];
	bool vis[1000010];
	signed main() {
		int l, r, tot = 0;
		cin >> l >> r;
		vis[0] = vis[1] = true;
		for (int i = 2; i <= min(1000000, r); ++i) {
			if (!vis[i]) {
				a[++tot] = i;
			}
			for (int j = 1; j <= tot && i * a[j] <= min(1000000, r); ++j) {
				vis[i * a[j]] = true;
				if (i % a[j] == 0) break;
			}
		}
		LL cnt = 0;
		if (r > 1000000) {
			for (int j = 1; j <= tot; ++j) {
				for (int i = 1; i * a[j] <= r; ++i) {
					++cnt;
				}
			}
			for (int i = 1; i < l; ++i) {
				if (!vis[i]) --tot; 
			}
			cout << tot + (r - 1000000LL - cnt) << endl;
		} else {
			LL ans = 0;
			for (int i = l; i <= r; ++i) {
				if (!vis[i]) {
					++ans;
				}
			}
			cout << ans << endl;
		}
	    return 0;
	}
};

signed main()
{
	return gdb7::main();
}


2025/2/7 21:54
加载中...