打卡信奥刷题(255)用Scratch图形化工具信奥P9825 [普及组][ICPC2020 Shanghai R] Fibonacci

[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=fn2+fn1(n3)

因此,数列的前一些项为 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 xy 为偶数,则函数 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=1nj=i+1ng(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=fn2+fn1 (n3).

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=1nj=i+1ng(fi,fj), where g ( x , y ) = 1 g(x,y) = 1 g(x,y)=1 when x ⋅ y x \cdot y xy 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 (1n109).

输出格式

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=1nj=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考级编程题实现、白名单赛事考题实现,感兴趣的请关注,我后续将继续分享相关内容

  • 7
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值