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

边栏推荐
- TCL: Pin Constraints Using the tcl Scripting Language in Quartus
- 思维导图,UML在线画图工具
- Grid false data injection attacks detection based on coding strategy
- Multidimensional Correlation Time Series Modeling Method Based on Screening Partial Least Squares Regression of Correlation Variables
- After reshipment tencent greetings to monitor if the corresponding service does not exist by sc. Exe command to add services
- CRS management and maintenance
- els block boundary deformation processing
- nodeJs--mime module
- The Statement update Statement execution
- What is it like to trade for a living?
猜你喜欢

玩转NFT夏季:这份工具宝典值得收藏

uni-app project summary

146. LRU cache

Using the "stack" fast computing -- reverse polish expression

c语言字符和字符串函数总结(二)

Quick solution for infix to suffix and prefix expressions

Redis - message publish and subscribe

Unknown CMake command “add_action_files“

Short video seo search optimization main content

TCL: Pin Constraints Using the tcl Scripting Language in Quartus
随机推荐
工业信息物理系统攻击检测增强模型
Kotlin协程:创建、启动、挂起、恢复
IO流基础
08-SDRAM: Summary
Redis-消息发布订阅
Active Disturbance Rejection Control of Substation Inspection Robot Based on Data Drive
JSP built-in object out object function introduction
Microsoft PC Manager V2.1 beta version officially released
What does the errorPage attribute of the JSP page directive do?
磁盘与文件系统管理
信息物理系统状态估计与传感器攻击检测
String splitting function strtok exercise
【21天学习挑战赛】顺序查找和二分查找的小总结
After reshipment tencent greetings to monitor if the corresponding service does not exist by sc. Exe command to add services
Detailed explanation of JSP request object function
JSP out.println()方法具有什么功能呢?
els block boundary deformation processing
460. LFU cache
IO stream basics
C language character and string function summary (2)