Codevs 2669 Simple Trials

Source: Internet
Author: User

2, Codevs 2669 Simple trials

Title Description Description

A number S is known to seek X and Y, making 2^x+3^y=s.

Enter a description input Description

(multiple sets of data)

Each line is an integer s, and the input ends when s=0.

Outputs description Output Description

X and Y, output in the form of 2^x+3^y=s, if there are multiple sets of solutions, output x the smallest group.

Sample input to sample

13

33

0

Sample output Sample Outputs

2^2+3^2=13

2^5+3^0=33

Data Size & Hint

For 30% data s≤50,000,000, the number of data groups ≤5000

For 50% data s≤3,000,000,000, the number of data groups ≤20000

For 80% data s≤3,000,000,000,000, the number of data groups ≤50000

For 100% data s≤200,000,000,000,000, the number of data groups ≤80000

#include <cstdio>#include<cmath>Long Longs;intmi3=0;BOOLJcLong LongX//determine whether the Mi3 of 3 can have integers with this power of 2{Mi3++; if(%3&&x!=1)//not a power of 3.{Mi3=0;//empty to calculate again        return 0; }     if(x==1)return 1;//conforms to the equation    Else(JC (x/3)); }Long LongKsmintKLong LongX//{        for(intI=1; i<=k;i++) x*=2; returnX//}intMain () {scanf ("%lld",&s);  while(s) {intJ=ceil (sqrt (s));//if the exponent of the s,2 is only composed of 2, the index will never exceed J//the following loops do not go to J, so don't worry s-k will be less than 0         for(intI=0; i<=j;i++)        {            Long LongK=KSM (I,1); if(JC (S-K))//because the problem as long as the output of the smallest x, so long as I meet the conditions, the output can be directly out{printf ("2^%d+3^%d=%lld\n", i,mi3-1, s); Mi3=0;  Break; }} scanf ("%lld",&R); }    return 0; }

Codevs 2669 Simple Trials

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.