⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ac1023.pas

📁 uralcode
💻 PAS
字号:
{We can prove that l=d-1, where d is the least divisor of k but larger than 2.
 Proof:
   1) Let l+1 be a divisor of k. At each step, if 1P takes n buttons, 2P can
      take (l+1-n) buttons, making the number of remaining buttons still a
      multiple of l+1. In the end 2P can take the last button.
   2) Let l+1 be not a divisor of k, and let r be k mod (l+1). Obviously r<>0.
      So at the first step 1P can take r buttons, confronting 2P with the
      situation stated in case 1). In the end 2P will lose.}
program ural1023;
var
  k,i:longint;
begin
  readln(k);
  for i:=3 to trunc(sqrt(k)) do
    if k mod i=0 then begin
      writeln(i-1);
      halt;
    end;
  if (k mod 2=0) and (k>5) then writeln(k div 2-1) else writeln(k-1);
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -