Codeforces Round #774 E
这道题感觉没有E平时的难度
首先我们感性理解一下 相交的数只有可能是 一个数的幂次才能相交 比如 2 4 8;3 9 27;
然后我们把他们行单独提出来 再观察一下幂次 发现其实都是一样的
比如第一行都是 1 2 3 4 5
比如第二行都是 2 4 6 8 10
这样我们最坏的情况下就只用处理20行 2^20>1e6 我们用mp[i]表示 如果又i行幂次行 有多少个数 O(20*m)
然后再枚举每一个i有多少个幂次行 加上即可
#include <bits/stdc++.h>
using namespace std;
const int N =1e6+10;
const int M = 998244353;
const int mod = 998244353;
#define int long long
#define endl '\n'
#define Endl '\n'
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define _ 0
#define inf 0x3f3f3f3f3f3f3f3f
#define fast ios::sync_with_stdio(false);cin.tie(nullptr);
int qpow(int a,int k){
int res=1;
while(k){
if(k&1)res=res*a;
k>>=1;
a=a*a;
}
return res;
}
int mp[21];
bool vis[N],st[N*20];
void solve(){
int n,m;cin>>n>>m;
int cnt=0;
for(int i=1;i<=20;i++){
for(int j=1;j<=m;j++){
if(!st[i*j])cnt++;
st[i*j]=1;
}
mp[i]=cnt;
}
int ans=1;
for(int i=2;i<=n;i++){
if(vis[i])continue;
int j=i,cnt1=0;
while(j<=n)vis[j]=1,j*=i,cnt1++;
ans+=mp[cnt1];
}
cout<<ans<<endl;
}
signed main(){
fast
int T;T=1;
while(T--) {
solve();
}
return ~~(0^_^0);
}

浙公网安备 33010602011771号