[找规律]Fibonacci 第45届icpc区域赛上海站G

In mathematics, the Fibonacci numbers, commonly denoted as f_nfn​, is a sequence such that each number is the sum of the two preceding numbers, starting with 11 and 11. That is, f_1 = 1, f_2 = 1f1​=1,f2​=1 and 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,\ldots1,1,2,3,5,8,13,21,… .

Given nn, please calculate \sum_{i=1}^{n}{\sum_{j=i+1}^{n}{g(f_i,f_j)}}∑i=1n​∑j=i+1n​g(fi​,fj​), where g(x,y) = 1g(x,y)=1 when x \cdot yx⋅y is even, otherwise g(x,y) = 0g(x,y)=0.

Input

The only line contains one integer n~(1\le n\le 10^9)n (1≤n≤109).

Output

Output one number – \sum_{i=1}^{n}{\sum_{j=i+1}^{n}{g(f_i,f_j)}}∑i=1n​∑j=i+1n​g(fi​,fj​).

Examples

Input

3

Output

2

Input

10

Output

24

Input

100

Output

2739

题意: 在前n个斐波那契数中选取两个数,如果两数乘积为偶数答案就加一,求最终答案。

分析: 列出斐波那契数:1 1 2 3 5 8 13......可以发现数列奇偶性满足奇奇偶 奇奇偶...的规律,因此可以三个数分一组,由于乘积为偶数的情况只有偶乘偶和奇乘偶两种情况,可以分别计算出结果然后相加。对于偶乘偶的情况,因为每组只有一个偶数,情况数就是从t组中选2组的组合数,也就是C(t, 2)。对于奇乘偶的情况,情况数为奇数的个数乘偶数的个数,也就是(2*t+n%3)*t,其中2*t+n%3为奇数的个数,t为偶数的个数。两种情况总和即为答案。

具体代码如下:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#define int long long
using namespace std;
//1 1 2 3 5 8......
//奇奇偶 奇奇偶...... 
//偶*偶的情况:C(t, 2)
//奇*偶的情况:(2*t+n%3)*t
signed main()
{
	int n;
	cin >> n;
	int t = n/3;
	int ans = t*(t-1)/2 + (2*t+n%3)*t;
	cout << ans;
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值