[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

解析

找规律即可,斐波那契数列三个一组,奇奇偶,然后计算即可
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+5;
int n,a[N]; 
void solve(){
	scanf("%lld",&n);
	int x=n/3;
	int y=n%3;
	printf("%lld",x*(x+1)+x*y+x*(x-1)*3/2);
}
signed main(){
	int t=1;
//	scanf("%lld",&t);
	while(t--) solve();
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值