当前位置:网站首页>Judging the number of leap years from 1 to N years
Judging the number of leap years from 1 to N years
2022-06-25 14:50:00 【䨁 逦】
According to the current calendar ( Gregorian calendar ): Leap every four years , Every hundred years does not leap , Leap every 400 years .
namely : The number of years is 4 It's not a multiple of 100 Multiple , Or years 400 Multiple , It's a leap year , The rest are ordinary years .
Please write the program , Year of importation y, Calculate ad 1 Year to y The total number of leap years in a year n.
Input format
y
Output format
n
sample input
1995
My original code
#include<stdio.h>
int ruennian(int x){
long long n=0;
for(long long i=1;i<=x;i++){
if((i%4 == 0 &&i%100!= 0)||(i%400 == 0))
n++;
}
return n;
}
int main(){
long long x=0;
scanf("%d",&x);
long long c=ruennian(x);
printf("%d\n",c);
return 0;
Optimize the code
#include<stdio.h>
int main(){
long long n,a,b,c;
scanf("%ld",&n);
a=n/4;
b=n/100;
c=n/400;
printf("%ld\n",a-b+c);
return 0;
}
边栏推荐
- Partager les points techniques de code et l'utilisation de logiciels pour la communication Multi - clients socket que vous utilisez habituellement
- C language LNK2019 unresolved external symbols_ Main error
- dmsetup命令
- TSDB在民机行业中的应用
- Biscuit distribution
- The best time to buy and sell stocks
- In 2022, the score line of Guangdong college entrance examination was released, and several families were happy and several worried
- 电源自动测试系统NSAT-8000,精准高速可靠的电源测试设备
- Add the resources directory under test in idea
- Extend JS copy content to clipboard
猜你喜欢
Clinical chemistry | zhangjianzhong / Xu Jian develop single cell precision diagnosis and treatment technology for Helicobacter pylori
Report on Hezhou air32f103cbt6 development board
Gif动图如何裁剪?收下这个图片在线裁剪工具
Master XSS completely from 0 to 1
电源自动测试系统NSAT-8000,精准高速可靠的电源测试设备
Sequential programming 1
15 -- 最接近原点的 K 个点
From 408 to independent proposition, 211 to postgraduate entrance examination of Guizhou University
Two methods to rollback the code in pycharm to the specified version (with screenshot)
How to crop GIF dynamic graph? Take this picture online clipping tool
随机推荐
成员变量与局部变量的区别
PubSub JS library realizes "cross component" data transfer
15 -- 最接近原点的 K 个点
有哪个瞬间让你觉得这个世界出bug了?
[HBZ sharing] use of locksupport
New good friend Pinia, leading the new era of state management
Garbage collection mechanism
Clipboard tutorial
Get the parameters in the URL and the interchange between parameters and objects
The best screenshot tool in the world, color absorption tool snipaste
分饼干问题
Position (5 ways)
Build a minimalist gb28181 gatekeeper and gateway server, establish AI reasoning and 3D service scenarios, and then open source code (I)
Renix perf: detailed explanation of IP network performance test tools and test case parameters
Open a restaurant
Clinical chemistry | zhangjianzhong / Xu Jian develop single cell precision diagnosis and treatment technology for Helicobacter pylori
Application of TSDB in civil aircraft industry
HMS Core机器学习服务实现同声传译,支持中英文互译和多种音色语音播报
How to make GIF animation online? Try this GIF online production tool
Cool assembly tutorial - concise x86 assembly language tutorial (1)