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