program slo; // listopad 2016, runda próbna type Ti=longint; Tq=qword; Tlitera= array['a'..'c'] of char; var n,na,i:Ti; k,ka:Tq; wa:char; //wa:wezeł aktualny sq2: array[1..1000000] of Tq;//potęgi 2-ki sucL: Tlitera = ('b','a','a'); sucP: Tlitera = ('c','c','b'); begin readln(n,k); na:=n; ka:=k; sq2[1]:=2; for i:=2 to 60 do sq2[i]:=sq2[i-1]*2; for i:= 61 to n do sq2[i]:=sq2[i-1]+2; // writeln(sq2[60]); writeln(sq2[60]*2); if k>3*(sq2[n]-1) then begin writeln('NIE'); exit end; if k<sq2[n] then wa:='a' else if k<2*sq2[n]-1 then wa:='b' else wa:='c'; case wa of 'b': ka-=sq2[na]-1; 'c': ka-=2*(sq2[na]-1) end; //case write(wa); while ka>1 do begin if ka<=sq2[na-1] then wa:=sucL[wa] else begin wa:=sucP[wa]; ka:=ka-sq2[na-1]+1 end; ka-=1; na-=1; write(wa); end; //while writeln; end.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | program slo; // listopad 2016, runda próbna type Ti=longint; Tq=qword; Tlitera= array['a'..'c'] of char; var n,na,i:Ti; k,ka:Tq; wa:char; //wa:wezeł aktualny sq2: array[1..1000000] of Tq;//potęgi 2-ki sucL: Tlitera = ('b','a','a'); sucP: Tlitera = ('c','c','b'); begin readln(n,k); na:=n; ka:=k; sq2[1]:=2; for i:=2 to 60 do sq2[i]:=sq2[i-1]*2; for i:= 61 to n do sq2[i]:=sq2[i-1]+2; // writeln(sq2[60]); writeln(sq2[60]*2); if k>3*(sq2[n]-1) then begin writeln('NIE'); exit end; if k<sq2[n] then wa:='a' else if k<2*sq2[n]-1 then wa:='b' else wa:='c'; case wa of 'b': ka-=sq2[na]-1; 'c': ka-=2*(sq2[na]-1) end; //case write(wa); while ka>1 do begin if ka<=sq2[na-1] then wa:=sucL[wa] else begin wa:=sucP[wa]; ka:=ka-sq2[na-1]+1 end; ka-=1; na-=1; write(wa); end; //while writeln; end. |