9118[春测]幂次方
zzz99947937 · · 个人记录
题面
[春季测试 2023] 幂次
题目描述
小 Ω 在小学数学课上学到了“幂次”的概念:
她很好奇有多少正整数可以被表示为上述
因此她想知道在
输入格式
第一行包含两个正整数
输出格式
输出一行包含一个非负整数表示对应的答案。
样例 #1
样例输入 #1
99 1
样例输出 #1
99
样例 #2
样例输入 #2
99 3
样例输出 #2
7
样例 #3
样例输入 #3
99 2
样例输出 #3
12
提示
【样例 2 解释】
以下是全部
注意某些正整数可能有多种合法的表示方法,例如
但根据题意,同一个数的不同的合法表示方法只会被计入一次。
【样例 3 解释】
以下是全部
【样例 4】
见选手目录下的 power/power4.in 与 power/power4.ans。
【样例 5】
见选手目录下的 power/power5.in 与 power/power5.ans。
【样例 6】
见选手目录下的 power/power6.in 与 power/power6.ans。
【数据范围】
对于所有数据,保证
| 测试点编号 | ||
|---|---|---|
| 1 | ||
| 2 | ||
| 3 | ||
| 4 | ||
| 5 | ||
| 6 | ||
| 7 | ||
| 8 | ||
| 9 | ||
| 10 | ||
| 11 | ||
| 12 | ||
| 13 | ||
| 14 | ||
| 15 | ||
| 16 | ||
| 17 | ||
| 18 | ||
| 19 | ||
| 20 |
赛时思路:暴力但是寄了
只有不可以总司令的5分
#include<bits/stdc++.h>
using namespace std;
long long szt[500005];
long long n,k,m,sum;
long long po(long long aa,long long bb){
long long x=1;
for(int i=0;i<bb;i++){
x*=aa;
}
return x;
}
bool chek(int p,long long q){
for(int i=0;i<p;i++){
if(q==szt[p]){
return false;
}
}
return true;
}
int main(){
freopen("power.in","r",stdin);
freopen("power.out","w",stdout);
cin>>n>>k;
if(k==1){
cout<<n;
return 0;
}
long long lx=1;
int y=0;
while(lx<=n){
lx*=2;
m++;
if(m>=k){
szt[y]=lx;
y++;
}
}
m--;
if(m<k){
cout<<1;
return 0;
}
if(m==k){
cout<<2;
return 0;
}
sum=2+m-k;
int zjx=0;
for(int i=k;i<=m;i++){
int j=2;
while(po(j+1,i)<=n){
j++;
long long z=po(j+1,i);
if(chek(y,z)){
szt[y]=z;
y++;
zjx++;
cout<<z<<endl;
}
}
}
cout<<sum<<" "<<zjx<<endl;
sum+=zjx;
cout<<sum;
return 0;
}
第一次提交:35(先写k==3的情况)
#include<bits/stdc++.h>
#define ll long long
using namespace std;
map<ll,bool> mp;
int c,tot;
int main(){
ll n,k;
cin>>n>>k;
if(k==1){
cout<<n;
return 0;
}
for(ll i=2;i*i*i<=n;i++){
ll s=i*i;
while(s*i<=n){
s*=i;
if(mp[s]){
continue;
}
mp[s]=1;
tot++;
}
}
if(k==3){
cout<<tot+1;
}
return 0;
}
但是因为15行while循环条件过于玄学,最后几个点T了 改为s<=n/i即可再得10分 )
颜色不错
正解(但又不是完全正解,只能怪ccf数据太离谱):加上k==2的情况
#include<bits/stdc++.h>
#define ll long long
using namespace std;
map<ll,bool> mp;
int c,tot;
int main(){
ll n,k;
cin>>n>>k;
if(k==1){
cout<<n;
return 0;
}
for(ll i=2;i*i*i<=n;i++){
ll s=i*i;
while(s<=n/i){
s*=i;
ll x=sqrtl(s);
if(mp[s]){
continue;
}
if(x*x==s){
c++;
}
mp[s]=1;
tot++;
}
}
if(k==3){
cout<<tot+1;
}
if(k==2){
cout<<tot+(ll)sqrtl(n)-c;
}
return 0;
}
玄学开根函数,只写sqrt还会T最后一个点