Codeforce Round #538(Div2)

比赛链接:https://codeforces.com/contest/1114

B.(字丑求轻喷QAQ)

 1 #include<bits/stdc++.h>
 2 #define ll long long
 3 #define pii pair<int,int>
 4 using namespace std;
 5 const int maxn=2e5+6;
 6 vector<pii>v;
 7 int n,m,k;
 8 int main()
 9 {
10     cin>>n>>m>>k;
11     for(int i=1;i<=n;++i)
12     {
13         int a;cin>>a;
14         v.push_back(make_pair(a,i));
15     }
16     sort(v.begin(),v.end(),greater<pii>());
17     ll sum=0;
18     vector<int>div;
19     for(int i=0;i<m*k;++i)
20     {
21         sum+=v[i].first;
22         div.push_back(v[i].second);
23     }
24     cout<<sum<<endl;
25     sort(div.begin(),div.end());
26     for(int i=m-1;i<div.size()-1;i+=m)
27     {
28         printf("%d ",div[i]);
29     }
30     return 0;
31 }

 

    

C.

 1 #include<bits/stdc++.h>
 2 #define ll long long
 3 using namespace std;
 4 ll n,b;
 5 int main()
 6 {
 7     cin>>n>>b;
 8     ll ans=1e18;
 9     for(ll i=2;i<=b;++i)
10     {
11         ll cnt=0;
12         if(i*i>b) i=b;
13         while(b%i==0) {cnt++;b/=i;}
14         if(cnt==0) continue;
15         ll tmp=0,base=1;            //    ll tmp=0;base=i;
16         while(base<=n/i)            //    while(base<=n)
17         {                            //    {
18             base*=i;                //        tmp+=n/base;
19             tmp+=n/base;            //        base*=i;
20         }                            //    }
21         ans=min(ans,tmp/cnt);        //    这样看起来更好理解,但是...爆了long long,要修改
22     }
23     cout<<ans<<endl;
24 }

 

  

猜你喜欢

转载自www.cnblogs.com/codeoosacm/p/10374135.html
0条评论
添加一条新回复
  
今日推荐