Anumberthatwillbethesamewhenitiswrittenforwardsorbackwardsisknownasa PalindromicNumber.Forexample,1234321isapalindromicnumber.Allsingledigitnumbersarepalindromicnumbers.
Althoughpalindromicnumbersaremostoftenconsideredinthedecimalsystem,theconceptofpalindromicitycanbeappliedtothenaturalnumbersinanynumeralsystem.Consideranumber N>0 inbase b≥2,whereitiswritteninstandardnotationwith k+1 digits ai as ∑i=0k(aibi).Here,asusual, 0≤ai<b forall i and ak isnon-zero.Then N ispalindromicifandonlyif ai=ak−i forall i.Zeroiswritten0inanybaseandisalsopalindromicbydefinition.
Givenanypositivedecimalinteger N andabase b,youaresupposedtotellif N isapalindromicnumberinbase b.
InputSpecification:
Eachinputfilecontainsonetestcase.Eachcaseconsistsoftwopositivenumbers N and b,where 0<N≤109 isthedecimalnumberand 2≤b≤109 isthebase.Thenumbersareseparatedbyaspace.
OutputSpecification:
Foreachtestcase,firstprintinoneline Yes if N isapalindromicnumberinbase b,or No ifnot.Theninthenextline,print N asthenumberinbase b intheform"ak ak−1 ... a0".Noticethattheremustbenoextraspaceattheendofoutput.
SampleInput1:272SampleOutput1:Yes11011SampleInput2:1215SampleOutput2:No441#include<iostream>#include<string>#include<sstream>#include<vector>#include<algorithm>#include<cmath>usingnamespacestd;//9:15boolisP(intk){ints=pow(k,0.5);if(k==0||k==1)returnfalse;for(inti=2;i<=s;i++){if(k%i==0)returnfalse;}returntrue;}intmain(){//freopen("C:\\Users\\chenzhuo\\Desktop\\in.txt","r",stdin);intnum;cin>>num;intd;cin>>d;inttmp=num;intans[50];intidx=0;while(tmp>0){ans[idx++]=tmp%d;tmp=tmp/d;}intid=idx;intflag=1;for(inti=0,j=idx-1;i<j;i++,j--){if(ans[i]!=ans[j]){cout<<"No"<<endl;flag=0;break;}}if(flag){cout<<"Yes"<<endl;}for(inti=id-1;i>=0;i--){cout<<ans[i];if(i!=0)cout<<"";}}