当前位置:网站首页>第 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很有可能已经溢出了,后面则是转化后再相加,不会溢出。
看来学好语法基础知识很重要呀!

边栏推荐
- nodeJs--mime模块
- Knowing the inorder traversal of the array and the preorder traversal of the array, return the postorder history array
- bgp 聚合 反射器 联邦实验
- Disk and file system management
- 工业信息物理系统攻击检测增强模型
- What is it like to trade for a living?
- Simpson's paradox
- 2022/08/01 Study Notes (day21) Generics and Enums
- Business test how to avoid missing?
- NFT工具合集
猜你喜欢

Are test points the same as test cases?

GIF making - very simple one-click animation tool

Redis - message publish and subscribe

Don't know about SynchronousQueue?So ArrayBlockingQueue and LinkedBlockingQueue don't and don't know?

String splitting function strtok exercise

nodeJs--mime module

unity2D横版游戏教程5-UI

鲲鹏编译调试插件实战

How to find new potential projects?Tools recommended

玩转NFT夏季:这份工具宝典值得收藏
随机推荐
PHP to read data from TXT file
Automatic conversion of Oracle-style implicit joins to ANSI JOINs using jOOQ
08-SDRAM: Summary
测试点等同于测试用例吗
What does the errorPage attribute of the JSP page directive do?
JSP out.write()方法具有什么功能呢?
Routing strategy
这 4 款电脑记事本软件,得试试
PHP从txt文件中读取数据的方法
Kunpeng compile and debug plug-in actual combat
ROS 动态参数
构造方法,this关键字,方法的重载,局部变量与成员变量
uni-app项目总结
Day11 shell脚本基础知识
Quick solution for infix to suffix and prefix expressions
bgp aggregation reflector federation experiment
Using the "stack" fast computing -- reverse polish expression
基于注意力机制的多特征融合人脸活体检测
Kotlin协程:创建、启动、挂起、恢复
2022/08/01 Study Notes (day21) Generics and Enums