[ICPC2020 Shanghai R] Fibonacci
题面翻译
在数学中,斐波拉契数列常被记为数列 f n f_n fn。该数列的首项 f 1 , f 2 f_1,f_2 f1,f2 均为 1 1 1,并满足递推公式 f n = f n − 2 + f n − 1 ( n ≥ 3 ) f_n=f_{n-2}+f_{n-1}(n\ge 3) fn=fn−2+fn−1(n≥3)。
因此,数列的前一些项为 1 , 1 , 2 , 3 , 5 , 8 , 13 , 21 , ⋯ 1,1,2,3,5,8,13,21,\cdots 1,1,2,3,5,8,13,21,⋯。
若 x ⋅ y x\cdot y x⋅y 为偶数,则函数 g ( x , y ) = 1 g(x,y)=1 g(x,y)=1,否则 g ( x , y ) = 0 g(x,y)=0 g(x,y)=0。求 ∑ i = 1 n ∑ j = i + 1 n g ( f i , f j ) \sum\limits_{i=1}^n{\sum\limits_{j=i+1}^n{g(f_i,f_j)}} i=1∑nj=i+1∑ng(fi,fj) 的值。
题目描述
In mathematics, the Fibonacci numbers, commonly denoted as f n f_n fn, is a sequence such that each number is the sum of the two preceding numbers, starting with 1 1 1 and 1 1 1. That is, f 1 = 1 , f 2 = 1 f_1 = 1, f_2 = 1 f1=1,f2=1 and f n = f n − 2 + f n − 1 ( n ≥ 3 ) f_n = f_{n-2} + f_{n-1}~(n \ge 3) fn=fn−2+fn−1 (n≥3).
Thus, the beginning of the sequence is 1 , 1 , 2 , 3 , 5 , 8 , 13 , 21 , … 1, 1, 2, 3, 5, 8, 13, 21,\ldots 1,1,2,3,5,8,13,21,… .
Given n n n, please calculate ∑ i = 1 n ∑ j = i + 1 n g ( f i , f j ) \sum_{i=1}^{n}{\sum_{j=i+1}^{n}{g(f_i,f_j)}} ∑i=1n∑j=i+1ng(fi,fj), where g ( x , y ) = 1 g(x,y) = 1 g(x,y)=1 when x ⋅ y x \cdot y x⋅y is even, otherwise g ( x , y ) = 0 g(x,y) = 0 g(x,y)=0.
输入格式
The only line contains one integer n ( 1 ≤ n ≤ 1 0 9 ) n~(1\le n\le 10^9) n (1≤n≤109).
输出格式
Output one number – ∑ i = 1 n ∑ j = i + 1 n g ( f i , f j ) \sum_{i=1}^{n}{\sum_{j=i+1}^{n}{g(f_i,f_j)}} ∑i=1n∑j=i+1ng(fi,fj).
样例 #1
样例输入 #1
3
样例输出 #1
2
样例 #2
样例输入 #2
10
样例输出 #2
24
样例 #3
样例输入 #3
100
样例输出 #3
2739
Scratch实现
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-9NxQ1YJ1-1720257228269)(https://i-blog.csdnimg.cn/direct/e1e21a972ccf4055b5417dc88fcb8d56.png)]
后续
接下来我会不断用scratch来实现信奥比赛中的算法题、Scratch考级编程题实现、白名单赛事考题实现,感兴趣的请关注,我后续将继续分享相关内容