Good Number ###K //K

题目链接:https://vjudge.net/contest/402831#problem/F

题意:问所有不超过n的数  取x开根号k次方向下取整 问 x能被 开根号的数整除的数有多少个

思路:因为开k次方  范围是1e9  所有有用的k不超过30   那么考虑分块一下   枚举从1~1e5

是开根号的数  然后 用除法算出有多少倍数即可 注意记录上一次处理到的位置 用前缀和思想减去

按段处理就行    注意大于1e9 break的时候别用快速幂写,不然会出问题  直接for1~30即可

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define ll long long
 4 #define pi pair<int,int>
 5 #define pb push_back
 6 #define fi first
 7 #define sc second
 8 #define ull unsigned long long
 9 const int maxn=4e5+10;
10 const int mod=998244353;
11 
12 
13 
14 int main()
15 {
16     ios::sync_with_stdio(0);
17     cin.tie(0);
18     int c=0;
19     int t;cin>>t;
20     while(t--)
21     {
22         int n,k;
23         cin>>n>>k;
24         int ans=0;
25         cout<<"Case #"<<++c<<": ";
26         if(k==1)
27         {
28             cout<<n<<'\n';
29             continue;
30         }
31         int be=0;
32         for(int i=2;i<=1e5;i++)
33         {
34             ll num=1;
35             int f=0;
36             for(int j=0;j<k;j++)
37             {
38                 num*=i;
39                 if(num>n)
40                 {
41                     f=1;
42                     break;
43                 }
44             }
45             if(f)
46             {
47                 int tmp=n;
48                 ans+=tmp/(i-1)-be/(i-1);
49                 break;
50             }
51             int tmp=num-1;
52             ans+=tmp/(i-1)-be/(i-1);
53             be=tmp;
54         }
55         cout<<ans<<'\n';
56     }
57 
58 
59 
60 
61 
62 
63 
64 }
View Code

 

posted @ 2020-10-20 12:43  canwinfor  阅读(219)  评论(0)    收藏  举报