跳到正文

题解

CF1646E 题解

intel_core约 1 分钟
原文
文章信息与版本

文章信息

发布
2022年8月20日
收录
2026年8月2日
更新
2026年11月3日
篇幅
约 1 分钟
获赞
7
题目
CF1646E

版本

  1. v1当前

注意到第 d,d2,d3,⋯ ,dk(k=⌊log⁡dn⌋)d,d^2,d^3,\cdots,d^k(k=\lfloor \log_d n\rfloor ) 行可以一起考虑。

对所有第 d,d2,d3,⋯ ,dkd,d^2,d^3,\cdots,d^k 行的数对 dd 取对数,不难发现贡献是 1×1,1×2,⋯ ,1×m,⋯ ,k×1,k×2,⋯ ,k×m1\times 1,1\times 2,\cdots,1\times m,\cdots,k\times 1,k\times 2,\cdots,k\times m 中不同数的个数。

上述贡献可以轻松 O(mlog⁡n)O(m\log n) 轻松求出。

总复杂度 O(mlog⁡n+n)O(m\log n+n)。

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int NR=1e6+10;
int n,m,ans=1,a[30],vis[NR],now;
bool buc[NR*20]; 
unordered_map<int,int>mp;

signed main(){
	cin>>n>>m;
	for(int i=1;i<=20;i++){
		for(int j=1;j<=m;j++)now+=buc[i*j]^1,buc[i*j]=1;
		a[i]=now;
	}
	for(int i=2;i<=n;i++)
		if(!vis[i]){
			int x=i,cnt=0;
			while(x<=n)cnt++,vis[x]=1,x*=i;
			ans+=a[cnt];
		}
	cout<<ans<<endl;
	return 0;
}
原文
存档评论4 条抓取于