# Batcher Odd-Even Mergesort Sorting Network Generator
# https://en.wikipedia.org/wiki/Batcher_odd%E2%80%93even_mergesort
# https://en.wikipedia.org/wiki/Sorting_network
gen = lambda N: [
[
(i+j, i+j+(1<<k))
for j in range((1<<k)%(1<<p), N-(1<<k), 2<<k)
for i in range(min(1<<k, N-j-(1<<k)))
if (((i+j)^(i+j+(1<<k)))>>(p+1)) == 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Mathlib | |
| import Mwf | |
| namespace Divapprox | |
| /-- | |
| 目的: 整数除算近似の誤差関数 `Δ(D,A,B,x)` を定義する。 | |
| 定義: `Δ = ⌊x/D⌋ - ⌊⌊x/A⌋ * ⌊AB/D⌋ / B⌋` を `Int` の除算で実装する。 | |
| 入力/前提: D A B x : Int、_hD : 0 < D、_hA : 0 < A。 | |
| 出力: 型 `Int` の値を返す。 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """StLang@Lark 実行環境サンプル standalone版""" | |
| ### TODO: ここからを本番の問題用の正しいコードに書き換える | |
| PROGRAM = r""" | |
| # サンプルプログラム: 二項係数 nCk の計算 (N > 62 の時は演算オーバーフローする可能性あり) | |
| if N >= K # N < K の時の出力は 0 とする | |
| $0 = 1 | |
| $1 = 1 | |
| $2 = N | |
| while $1 <= K # for $1 in 1..=K |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """StLang@Lark 実行環境サンプル standalone版""" | |
| ### TODO: ここからを本番の問題用の正しいコードに書き換える | |
| PROGRAM = r""" | |
| # サンプルプログラム: 二項係数 nCk の計算 (N > 62 の時は演算オーバーフローする可能性あり) | |
| if N >= K # N < K の時の出力は 0 とする | |
| $0 = 1 | |
| $1 = 1 | |
| $2 = N | |
| while $1 <= K # for $1 in 1..=K |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
NewerOlder