Codeforces 689C Mike and chocolate thieves

Source: Internet
Author: User

Title Link: http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=412145

Topic: Given a number n, ask whether it is possible to obtain a minimum integer x, so that in the 1-x range, you can take the N group of T*k^3<=x. T,k is an arbitrary integer that needs to be equal to N to t,k in case of less than equals x, so that it satisfies the t*k^3<=x. If x exists, then output x, if x does not exist, then output-1.

Problem Solving Ideas:

First Look at k=2, (1,2,4,8)/(2,4,8,16)/(3,6,12,24) ....

K=3, (1,3,9,27)/(2,6,18,54) ...

For a certain k, within the X range, the maximum number of groups that can be obtained is x/(k^3), because the number of legal groups is monotonic and can be solved by a two-part method.

Two situations are well understood, when the current quantity is greater than the required quantity, then move the right edge, when the current quantity is less than the required quantity, then move the left edge, but equal, and is not necessarily the solution. Because the title requirement is the smallest integer solution that is valid, the right boundary continues to move.

Problem Solving Code:

#include <cstdio>#include<iostream>using namespacestd;#definell Long Longll Solve (ll N) {ll ans=0;  for(LL i=2;; i++)  {   if(n/(i*i*i) = =0) Break; Ans+=n/(i*i*i); }  returnans;}intMain () {ll m; Cin>>m;intflag=0; ll L=1, r=5e15,ans; while(l<=R) {ll mid= (l+r)/2; Long LongCnt=solve (mid); if(cnt>m) r=mid-1; Else if(cnt<m) l=mid+1; Else{ans=mid; Flag=1; R=mid-1; }} printf ("%lld\n", flag?ans:-1); return 0;}

Codeforces 689C Mike and chocolate thieves

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.