ABC 204 E ã«é¢é£ãã¾ãã
å®ç¾©
è¡¨è¨ | æå³ | ä¾ |
---|---|---|
$\floor{x}$ | $x$ 以ä¸ã®æ大ã®æ´æ° | $\floor{3.1} = 3$, $\floor{2.7} = 2$, $\floor{-2.2} = -3$, $\floor{2} = 2$ |
$\ceil{x}$ | $x$ 以ä¸ã®æå°ã®æ´æ° | $\ceil{3.1} = 4$, $\ceil{2.7} = 3$, $\ceil{-2.2} = -2$, $\ceil{2} = 2$ |
$\rounded{x}$ | $x$ ã«æãè¿ãæ´æ° | $\rounded{3.1} = 3$, $\rounded{2.7} = 3$, $\rounded{-2.2} = -2$, $\rounded{2} = 2$ |
ãã ããããã§ã¯ãæ´æ° $n$ ã«å¯¾ã㦠$\rounded{n + 0.5}$ ã¯æªå®ç¾©ã¨ãã¾ããããªãã¡ã以ä¸ã®ã¹ã¿ã³ã¹ã¨ãããã¨ã§ãã
- ãã®è¨äºä¸ã§ $\rounded{x}$ ãèããã¨ã㯠$x - \floor{x} \neq 0.5$ ã示ãå¿ è¦ãããã
- $\rounded{n + 0.5} = n$ ããã㯠$\rounded{n + 0.5} = n + 1$ ã®ããã«æ¡å¼µããé¢æ°ã§ãããã®è¨äºã§ç¤ºããæ§è³ªã¯æãç«ã¤ã
å®çã¨è£é¡ãã¡
Lemma 1: $\ForallL{n\in\N}{\sqrt{n}-\floor{\sqrt{n}} \neq 1/2}$
Proof
èçæ³ã«ããã ããéè² æ´æ° $n$ ã«å¯¾ããæ´æ° $m$ ãåå¨ã㦠$\sqrt{n} = m+1/2$ ãæãç«ã¤ã¨ä»®å®ããã $$n = (m+1/2)^2 = m^2+m+1/4$$ ããã$n\in\Z$ ã㤠$n\notin\Z$ ãæãç«ã¤ã®ã§çç¾ã$\qed$
Lemma 2: $$ \ForallL{x\in\R}{x\ge 0\implies -\tfrac12+\sqrt{\tfrac14+x}\le \sqrt{x} \lt \left(-\tfrac12+\sqrt{\tfrac14+x}\right)+\tfrac12} $$
Proof
å³å´ã¯ $\sqrt{x} \lt \sqrt{x+\tfrac14}$ ããæããã以ä¸ãå·¦å´ã示ãã $$ \begin{aligned} -\tfrac12 + \sqrt{\tfrac14 + x} &\le -\tfrac12 + \sqrt{\left(\tfrac12+\sqrt{x}\right)^2} \\ &= -\tfrac12 + \left|\tfrac12 + \sqrt{x}\right| \\ &= \sqrt{x}. \qquad\qed \end{aligned} $$
Theorem 3: $$ \ForallL{n\in\N}{\Ceil{-\tfrac12+\sqrt{\tfrac14+n}} = \rounded{\sqrt{n}}} $$
Proof
ä»»æã«åºå®ãã $n\in\N$ ã«å¯¾ãã$m = \Ceil{-\tfrac12+\sqrt{\tfrac14+n}}$ ã¨ããã ãã®ã¨ãã$m-\tfrac12 \lt \sqrt{n} \lt m+\tfrac12$ ã示ãã°ããã
å³å´ã¯ Lemma 2 ããå¾ãã®ã§ã以ä¸ã§ã¯å·¦å´ã示ãã $n = 0$ ã®ã¨ãæããã«æãç«ã¤ã®ã§ãä»¥ä¸ $n \gt 0$ ã¨ããããã®ã¨ã $m \ge 1$ ã§ãããã¨ã«æ³¨æããã $m$ ã®å®ç¾©ãã $m-1 \lt -\tfrac12 + \sqrt{\tfrac14+n}$ ãªã®ã§ã $$ \begin{aligned} m-1 &\lt -\tfrac12 + \sqrt{\tfrac14+n} \\ m - \tfrac12 & \lt \sqrt{\tfrac14+n} \\ n & \gt (m-\tfrac12)^2-\tfrac14 \\ &= m^2-m \end{aligned} $$ ã¨ãªããæ´æ°æ§ãã $n\ge m^2-m+1$ ãªã®ã§ã $$ \begin{aligned} n &\ge m^2-m+1 \\ &\gt (m-\tfrac12)^2 \\ m-\tfrac12 &\lt \sqrt{n}.\qquad\qed \end{aligned} $$
Lemma 4: $\ForallL{n\in\N}{n\le \floor{\sqrt{n}}\floor{\sqrt{n}+1} \iff \sqrt{n} \lt \floor{\sqrt{n}}+\tfrac12}$
Proof
$m = \floor{\sqrt{n}}$ ã¨ããã
($\implies$) 対å¶ã示ãã$\sqrt{n}\ge m+\tfrac12 \implies n \gt m(m+1)$ ã示ãã $$ \begin{aligned} n &\ge (m+\tfrac12)^2 \\ &= m^2+m+\tfrac14 \\ &\gt m(m+1). \end{aligned} $$
($\impliedby$) $\sqrt{n}\lt m+\tfrac12 \implies n \le m(m+1)$ ã示ãã $$ \begin{aligned} n &\lt (m+\tfrac12)^2 \\ &= m^2 + m + \tfrac14 \end{aligned} $$ æ´æ°æ§ããã$n \le m^2+m$ ãå¾ãã$\qed$
Lemma 5: $$\ForallL{n\in\N}{n\gt 0, n\le\floor{\sqrt{n}}\floor{\sqrt{n}+1} \implies \frac{n}{\floor{\sqrt{n}}} \le \frac{n}{\floor{\sqrt{n}+1}} + 1}$$
Proof
$m = \floor{\sqrt{n}}$ ã¨ããã対å¶ãèããã $n/m \gt n/(m+1)+1 \implies n\gt m(m+1)$ ã示ãã $$ \begin{aligned} n(m+1) &\gt nm + m(m+1) \\ n &\gt m(m+1). \qquad\qed \end{aligned} $$
Lemma 6: $$\ForallL{n\in\N}{n\gt 0, n\le\floor{\sqrt{n}}\floor{\sqrt{n}+1} \implies \Floor{\frac{n}{\floor{\sqrt{n}+1}}} \lt \Floor{\frac{n}{\floor{\sqrt{n}}}}}$$
Proof
$m = \floor{\sqrt{n}}$ ã¨ããã$n = m(m+1)$ ã®ã¨ãã¯æãããªã®ã§ã$n \lt m(m+1)$ ã¨ããã $n\lt m(m+1) \implies \floor{\tfrac{n}{m+1}} \lt \floor{\tfrac nm}$ ã示ãã
$m = \floor{\sqrt{n}}$ ããã$m^2 = \floor{\sqrt{n}}^2 \le n$ ã§ããã $$ \Floor{\frac{n}{m+1}} \lt \frac{n}{m+1} \lt m \le \frac nm $$ ã¨ãªããæ´æ°æ§ãã $m\le \floor{\tfrac nm}$ ã§ããã$\floor{\tfrac{n}{m+1}}\lt \floor{\tfrac nm}$ ãå¾ãã$\qed$
Theorem 7: $$\ForallL{n\in\N}{n\gt 0, \Floor{\frac{n}{\floor{\sqrt{n}+1}}} + \floor{\sqrt{n}+1} = \Floor{\frac{n}{\rounded{\sqrt{n}}}} + \rounded{\sqrt{n}}}$$
Proof
$\floor{\sqrt{n}}+\tfrac12 < \sqrt{n}$ ã®ã¨ã $\floor{\sqrt{n}+1} = \rounded{\sqrt{n}}$ ã§ãããæããã«æãç«ã¤ã 以ä¸ã$\sqrt{n} \lt \floor{\sqrt{n}}+\tfrac12$ ã¨ããã ãã®ã¨ãã$\rounded{\sqrt{n}} = \floor{\sqrt{n}}$ ãªã®ã§ã以ä¸ã示ãã°ããã $$ \sqrt{n} \lt \floor{\sqrt{n}}+\frac12 \implies \Floor{\frac{n}{\floor{\sqrt{n}+1}}} + 1 = \Floor{\frac{n}{\floor{\sqrt{n}}}}. $$ $m = \floor{\sqrt{n}}$ ã¨ãããLemma 4 ããã$$n\le m(m+1) \implies \Floor{\frac{n}{m+1}}+1 = \Floor{\frac{n}{m}}$$ ã示ãã°ããã Lemma 5 ãã $$ \Floor{\frac nm}\le \frac nm\le \frac{n}{m+1}+1. $$ Lemma 6 ããã³æ´æ°æ§ãã $$ \Floor{\frac{n}{m+1}}\le \frac{n}{m+1}\lt \Floor{\frac nm} $$ ãªã®ã§ã $$ \Floor{\frac nm}\le \frac{n}{m+1} + 1 \lt \Floor{\frac nm} + 1 $$ ãæãç«ã¤ã ããªãã¡ã$\floor{\frac nm} = \floor{\frac{n}{m+1}}+1$ ã¨ãªãã$\qed$
Claim 8: $$\ForallL{n\in\N}{n\gt 0 \implies \floor{\sqrt{n}}\le \Floor{\frac{n}{\floor{\sqrt{n}}}} \le \floor{\sqrt{n}+2}}$$
Proof
$m = \floor{\sqrt{n}}$ ã¨ããã$m \le \sqrt{n} \lt m+1$ ã¨æ´æ°æ§ãã $m^2\le n\le m^2+2m$ ãæãç«ã¤ããã£ã¦ $m\le \floor{n/m}\le n/m\le m+2$ ãå¾ãã
ç³»
Corollary 9: Theorem 7 ãããABC 204 E å ¬å¼è§£èª¬ ã®ä¸ã§ $t = \rounded{\sqrt{D}}-1$ ã使ã£ã¦ããé¨åã§ã代ããã« $t = \floor{\sqrt{D}}$ ã使ããã¨ãã§ãã¾ãã
Corollary 10: äºåæ¢ç´¢ãç¨ãããã¨ã§ãæ´æ°ã®ç¯å²ã§ï¼æµ®åå°æ°ç¹æ°ã®æ¼ç®ãçµç±ããï¼$\floor{\sqrt{n}}$ ãæ±ãããããã¨ã¯æåã§ãããLemma 4 ãå©ç¨ãããã¨ã§ $\rounded{\sqrt{n}}$ ãæ´æ°ã®ç¯å²ã§æ±ãããã¨ãã§ãã¾ãã
fn rounded_sqrt(n: u64) -> u64 { let floor_sqrt = floor_sqrt(n); // ãããªã« match floor_sqrt.overflowing_mul(floor_sqrt + 1) { // n > floor_sqrt * (floor_sqrt + 1) ãªã floor_sqrt + 1 ã¨çãã (mul, false) if n > mul => floor_sqrt + 1, // ããã§ãªãå ´åï¼ç©ããªã¼ãã¼ããã¼ããå ´åãå«ãï¼ã¯ floor_sqrt ã¨çãã _ => floor_sqrt, } }
ãã®ä»
ä¸å¿ç¢ºèªã¨ã㦠$1\le n\le 10^9$ ã®ç¯å²ã§è«¸ã ã®å½é¡ãæãç«ã¤ãã¨ã確èªãã¦ããã®ã§ãããæ´æ°ã®å¹³æ¹æ ¹ã®è¨ç®ï¼ææ°æ¢ç´¢ã«ããï¼ãå«ãå ´å㯠30 ç§ç¨åº¦ãæµ®åå°æ°ç¹æ°ã®è¨ç®ã®ã¿ã®å ´å㯠3 ç§ç¨åº¦ã§æ¸ãã ã®ã§ã³ã£ãããã¾ããã
競ããããã¦ããã¨ãã®éãªæè¦ã ã¨ã$10^9$ åç¨åº¦ã®æ¼ç®ã¯ãããªãã®æéãããããããªæ°ããã¡ããã®ã§ï¼30 ç§ã¯ãããªãã®æéã§ããã¨ããè¦æ¹ãããããï¼ã
pâq ã示ããã¨ã㦠pâq 㨠¬qâ¬p ã示ãã¦ãã¾ãããã©ããã¦
— ãã³ã¡ããððð¦ (@rsk0315_h4x) August 19, 2023
証æãå¥ã®ã¨ããã§ä¸æ¸ããã¦ããè¨äºãæ¸ãå§ããã®ã§ãããä¸æ¸ãã® Lemma 4 ã®è¨¼æããããã¦ãã¦ç¦ãã¾ããã
ããã
ãããã§ããä¹ ã ã«é«æ ¡æ°å¦ããã£ãæ°ããã¾ãããåå¹´åã¯åã®å¾®åã¨ãããã£ã¦ãã¾ããã