当前位置:网站首页>Blue Bridge Cup 3 sequence summation
Blue Bridge Cup 3 sequence summation
2022-06-26 07:50:00 【Don't hit me, it hurts!】
explain : There are some test questions that give multiple sets of sample input and output to help you do better .
Generally, all these samples need to pass the test before they are submitted , But it doesn't mean that these groups of sample data are correct, and your program is completely correct , Potential mistakes may still lead to lower scores .
explain : Notice the size of the data here .
The direct idea of this problem is to directly use a cycle to accumulate , However , When the data scale is large , such “ violence ” This method often results in timeouts . At this point you need to think about other ways . You can try , If you use 1000000000 As input to your program , Can your program run within the time limit specified above .
Another point worth noting is that the size of the answer is not in the default integer of your language (int) Within the scope of , If you use integers to save results , It can lead to wrong results .
If you use C++ or C Language and ready to use printf Output results , Then your format string should be written as %I64d To output long long Type integer .
Code :
#include<iostream>
using namespace std;
int main()
{
int i,n;
long long sum=0;
cin>>n;
sum=(1+n)*((n*1.0)/2);
cout<<sum<<endl;
return 0;
}
The title is simple. , But pay attention to the running time limit , So find your own rules ,1+2+3+...+n=(1+n)*(n*1.0/2);
Also, the variables that save the final results should be able to store big data .(long long type )
边栏推荐
- How to define a digital factory and what is the relationship with smart factory and industry 4.0
- buuresevewp
- 4 best practices for wireless (OTA) updates
- What is the five levels of cultivation of MES management system
- [industry cloud talk live room] tomorrow afternoon! Focus on digital intelligence transformation of the park
- [UVM foundation] UVM_ Driver member variable req definition
- Solution to the problem of multi application routing using thinkphp6.0
- Real machine debugging of uniapp custom base
- Here is the command to display the disk space usage. Go ahead and pay attention to more wonderful things!
- A bold sounding and awesome operation - remake a Netflix
猜你喜欢

Web technology sharing | webrtc recording video stream

ASP. Net and Net framework and C #

Uniapp uses uviewui

Solution to the problem of multi application routing using thinkphp6.0

What are the key points of turnover box management in warehouse management

What is the difference between bone conduction earphones and ordinary earphones? Advantages of bone conduction earphones

Google Earth Engine(GEE) 01-中输入提示快捷键Ctrl+space无法使用的问题

OSPF design principles, commands take H3C as an example

Jmeter压力测试-Web代理本地接口测试【教学篇】

You can command Siri without making a sound! The Chinese team of Cornell University developed the silent language recognition necklace. Chinese and English are OK
随机推荐
Multi interface switching in one UI of QT
我想要股票账户优惠开户,如何操作?手机开户安全么?
Getdrawingcache of view is empty. Solution: interview questions for Android audio and video development
Encapsulating ranging and surface class based on leaflet
有序排列
arduino——ATtiny85 SSD1306 + DHT
Here is the command to display the disk space usage. Go ahead and pay attention to more wonderful things!
Kalman filter_ Recursive Processing
QT之一个UI里边多界面切换
Minor problems in importing D
Cloud native integration data warehouse heavy release
Uniapp wechat withdrawal (packaged as app)
Jemter 压力测试 -基础请求-【教学篇】
Opencv mouse event + interface interaction drawing rectangle polygon selection ROI
Apache inlong graduated as a top-level project with a million billion level data stream processing capability!
ASP. Net and Net framework and C #
Attention mechanism yyds, AI editor finally bid farewell to P and destroyed the whole picture
Redis (4) -- Talking about integer set
[UVM basics] connect of UVM_ Phase execution sequence
个人用指南针软件买股票安全吗?怎么炒股买股票呢