Datasets:
Tasks:
Text Generation
Modalities:
Text
Formats:
json
Languages:
English
Size:
< 1K
ArXiv:
Tags:
competitive-programming
code-generation
specification-generation
proof-generation
verification
rust
License:
File size: 1,199 Bytes
b2a430f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | use vstd::prelude::*;
fn main() {}
verus! {
pub struct Solution;
impl Solution {
pub open spec fn ways_mod(n: int, kind: int) -> int
decreases n,
{
if n <= 0 {
0
} else if n == 1 {
6
} else if kind == 0 {
(3 * Self::ways_mod(n - 1, 0) + 2 * Self::ways_mod(n - 1, 1)) % 1_000_000_007
} else {
(2 * Self::ways_mod(n - 1, 0) + 2 * Self::ways_mod(n - 1, 1)) % 1_000_000_007
}
}
pub fn num_of_ways(n: i32) -> (res: i32)
requires
1 <= n <= 5000,
ensures
0 <= res,
res as int == (Self::ways_mod(n as int, 0) + Self::ways_mod(n as int, 1)) % 1_000_000_007,
{
let modv: i64 = 1_000_000_007;
let mut a121: i64 = 6;
let mut a123: i64 = 6;
let mut i: i32 = 1;
while i < n {
let new_a121 = (3 * a121 + 2 * a123) % modv;
let new_a123 = (2 * a121 + 2 * a123) % modv;
a121 = new_a121;
a123 = new_a123;
i = i + 1;
}
((a121 + a123) % modv) as i32
}
}
} |