当前位置:网站首页>第 45 届ICPC亚洲区域赛(上海)G-Fibonacci
第 45 届ICPC亚洲区域赛(上海)G-Fibonacci
2022-08-02 00:13:00 【ZaneBobo】

题意:
题目链接(牛客网)点此查看原英文题目
你现在有一串斐波那契数列,然后定义一个g(x,y),如果x*y为偶数那么g(x,y)是1,否则的话是0,现在给你一个n,让你求
。
思路:
规律题,我们发现斐波那契数列是“奇奇偶奇奇偶”的一个规律三个一循环,然后再利用奇数偶数=偶数,奇数奇数=奇数,偶数偶数=偶数这个性质,计算就可以了。
代码:
#include<iostream>
using namespace std;
typedef long long LL;
int main()
{
long long n;
cin>>n;
long long a=n/3,aa=n%3;
long long sum1=a*2+aa,sum2=a;//sum1是奇数的个数,sum2是偶数的个数
LL sum=0;
sum+=sum1*sum2+sum2*(sum2-1)/2;//计算公式前面的奇数与偶数相乘的所有情况
//后面是偶数与偶数相乘的所有情况,后面用到了等差求和。
cout<<sum<<endl;
}这题因为long long wa了好多次,后来才知道(LL)(a+b)和((LL)a+(LL)b)根本不一样,前者只是把计算过后的a+b转化成LL 而此时a+b很有可能已经溢出了,后面则是转化后再相加,不会溢出。
看来学好语法基础知识很重要呀!

边栏推荐
- els block deformation
- Using the "stack" fast computing -- reverse polish expression
- How to find new potential projects?Tools recommended
- The Statement update Statement execution
- Realize deletion - a specified letter in a string, such as: the string "abcd", delete the "a" letter in it, the remaining "bcd", you can also pass multiple characters to be deleted, and pass "ab" can
- 业务测试如何避免漏测 ?
- 辨析内存函数memset、memcmp、memmove以及memcpy
- Multidimensional Correlation Time Series Modeling Method Based on Screening Partial Least Squares Regression of Correlation Variables
- uni-app project summary
- ROS dynamic parameters
猜你喜欢

Stapler:1 靶机渗透测试-Vulnhub(STAPLER: 1)

辨析内存函数memset、memcmp、memmove以及memcpy

测试用例:四步测试设计法

poker question

ICML 2022 || 局部增强图神经网络GNN,在 GCN 和 GAT基础上 平均提高了 3.4% 和 1.6%

Kunpeng compile and debug plug-in actual combat

nodeJs--各种路径

IP Core: FIFO
![[21-Day Learning Challenge] A small summary of sequential search and binary search](/img/81/7339a33de3b9e3aec0474a15825a53.png)
[21-Day Learning Challenge] A small summary of sequential search and binary search

Using the "stack" fast computing -- reverse polish expression
随机推荐
els 长条变形
[Solution] Emqx startup under win10 reports Unable to load emulator DLL, node.db_role = EMQX_NODE__DB_ROLE = core
Difference between JSP out.print() and out.write() methods
When Netflix's NFTs Forget Web2 Business Security
ROS 动态参数
Async/await principle and execution sequence analysis
nodeJs--各种路径
BGP first experiment
An interesting project--Folder comparison tool (1)
扑克牌问题
Are test points the same as test cases?
Short video SEO optimization tutorial Self-media SEO optimization skills and methods
PHP to read data from TXT file
632. Minimum interval
TCL: Pin Constraints Using the tcl Scripting Language in Quartus
回顾历史5次经济衰退时期:这一次可能会有何不同?
bgp aggregation reflector federation experiment
Interview high-frequency test questions solution - stack push and pop sequence, effective parentheses, reverse Polish expression evaluation
JSP request对象功能详解说明
测试用例:四步测试设计法