反素数范围不大,可以直接打表得
然后就是模拟移动的过程
我们可以用线段树优化,具体明天再说吧
1 const op:array[1..35] of longint=(1,2,4,6,12,24,36,48,60,120,180,240,360,720, 2 840,1260,1680,2520,5040,7560,10080,15120, 3 20160,25200,27720,45360,50400,55440,83160, 4 110880,166320,221760,277200,332640,498960); 5 fac:array[1..35] of longint=(1,2,3,4,6,8,9,10,12,16,18,20,24,30,32,36,40, 6 48,60,64,72,80,84,90,96,100,108,120,128,144, 7 160,168,180,192,200); 8 var tree:array[0..2000010] of longint; 9 a:array[0..500010] of longint; 10 nam:array[0..500010] of string[11]; 11 p,k,i,w,h,n,m:longint; 12 ch:char; 13 14 procedure build(i,l,r:longint); 15 var m:longint; 16 begin 17 if l=r then 18 tree[i]:=1 19 else begin 20 m:=(l+r) shr 1; 21 build(i*2,l,m); 22 build(i*2+1,m+1,r); 23 tree[i]:=tree[i*2]+tree[i*2+1]; 24 end; 25 end; 26 27 procedure work(i,l,r:longint); 28 var m:longint; 29 begin 30 if l=r then 31 tree[i]:=0 32 else begin 33 m:=(l+r) shr 1; 34 if k<=m then work(i*2,l,m) 35 else work(i*2+1,m+1,r); 36 tree[i]:=tree[i*2]+tree[i*2+1] 37 end; 38 end; 39 40 function sum(i,l,r:longint):longint; 41 var m:longint; 42 begin 43 if (1<=l) and (k>=r) then 44 exit(tree[i]) 45 else begin 46 m:=(l+r) shr 1; 47 sum:=0; 48 if m>=1 then sum:=sum+sum(i*2,l,m); 49 if k>m then sum:=sum+sum(i*2+1,m+1,r); 50 end; 51 end; 52 53 function ask(i,l,r:longint):longint; 54 var m:longint; 55 begin 56 if l=r then exit(l) 57 else begin 58 m:=(l+r) shr 1; 59 if w>tree[i*2] then 60 begin 61 w:=w-tree[i*2]; 62 exit(ask(i*2+1,m+1,r)); 63 end 64 else exit(ask(i*2,l,m)); 65 end; 66 end; 67 68 begin 69 while not eof do 70 begin 71 readln(n,k); 72 for i:=35 downto 1 do 73 if (op[i]<=n) then 74 begin 75 p:=i; 76 break; 77 end; 78 79 m:=n; 80 for i:=1 to n do 81 begin 82 nam[i]:=''; 83 read(ch); 84 while ch<>' ' do 85 begin 86 nam[i]:=nam[i]+ch; 87 read(ch); 88 end; 89 readln(a[i]); 90 end; 91 build(1,1,n); 92 93 for i:=1 to op[p]-1 do 94 begin 95 dec(m); 96 work(1,1,n); 97 if a[k]<0 then //分类讨论,找下一个人 98 begin 99 w:=-a[k]; 100 h:=sum(1,1,n); 101 if w<=h then 102 begin 103 w:=h-w+1; 104 k:=ask(1,1,n); 105 end 106 else begin 107 w:=(w-h-1) mod m+1; 108 w:=m-w+1; 109 k:=ask(1,1,n); 110 end; 111 end 112 else begin 113 w:=a[k]; 114 h:=sum(1,1,n); 115 if w<=m-h then 116 begin 117 w:=w+h; 118 k:=ask(1,1,n); 119 end 120 else begin 121 w:=w-(m-h); 122 w:=(w-1) mod m+1; 123 k:=ask(1,1,n); 124 end; 125 end; 126 end; 127 writeln(nam[k],' ',fac[p]); 128 end; 129 end.