アルゴリズムと数学 049

https://atcoder.jp/contests/math-and-algorithm/tasks/math_and_algorithm_ap

 10^7までなので、 O(N)の解法で十分ですね。
手元ではPythonのような、

(a, b) = (b, (a + b) % D)

というコードが通りましたが、AtCoderでは通りませんね。

// Fibonacci Easy (mod 1000000007)
#![allow(non_snake_case)]


//////////////////// constants ////////////////////

const D: i64 = 1000000007;


//////////////////// library ////////////////////

fn read<T: std::str::FromStr>() -> T {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).ok();
    line.trim().parse().ok().unwrap()
}


//////////////////// process ////////////////////

fn f(N: i64) -> i64 {
    let mut a: i64 = 1;
    let mut b: i64 = 1;
    for _ in 2..N {
//      (a, b) = (b, (a + b) % D)
        let tmp = a;
        a = b;
        b = (tmp + b) % D
    }
    b
}

fn main() {
    let N: i64 = read();
    println!("{}", f(N))
}