logo AlgoBeat OnlineJudge
登录 注册

题解

作者: _ZXY_  ·  发布于 2026-05-16 11:08:06  ·  最后修改于 2026-05-16 11:11:05
已通过
审核员:joe_zxq 彩笔 · 2026-05-16 11:11:05

奇妙数,其实就是分解质因数后,只有 的数。
我们可以写一个 dfs,每次将 乘上 ,判断是否访问过,加一下 就行了。

#include<bits/stdc++.h>
#define int long long

using namespace std;
int ans=0;
int l,r;
map<int,int>vis;
void dfs(int now){
	if (vis[now]) return;
	vis[now]=1;
	if(now>r)return;
	if(now>=l)ans++;
	dfs(now*2);
	dfs(now*3);
	dfs(now*5);
	dfs(now*7);
}
signed main(){
	cin>>l>>r;
	dfs(1);
	cout<<ans;
}

暂无评论

登录 后即可评论。