<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>sugarknri</author_name>
  <author_url>https://blog.hatena.ne.jp/sugarknri/</author_url>
  <blog_title>メモ</blog_title>
  <blog_url>https://sugarknri.hatenablog.com/</blog_url>
  <categories>
  </categories>
  <description>問題はこちら No.117 組み合わせの数 - yukicoder素直に階乗で計算するだけ C(N,K)はによる単純なループによりO(K)で計算できるけど、KTが大きいのでこれではTLEになる なので、事前に階乗を計算しておけば、各クエリは定数時間で答えられるP:=10^9+7は素数なので、K&lt;PにおいてK!はPを因数に持たず、互いに素であることから、mod PにおけるK!の逆元は存在する。 逆元はフェルマーの小定理により求める横着をして、階乗の逆元を毎回求めているのでちょっと遅い //繰り返し二乗法 long p(long a,int i){return i?p(a*a%P,i/2)*(i%…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fsugarknri.hatenablog.com%2Fentry%2F2016%2F12%2F06%2F053727&quot; title=&quot;yukicoder No.117 組み合わせの数 - メモ&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url>http://chart.apis.google.com/chart?cht=tx&amp;chl=%5Cprod_%7Bi%3D1%7D%5EK%20%5Cfrac%7BN%2B1-i%7D%7Bi%7D</image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2016-12-06 05:37:27</published>
  <title>yukicoder No.117 組み合わせの数</title>
  <type>rich</type>
  <url>https://sugarknri.hatenablog.com/entry/2016/12/06/053727</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
