当前位置:网站首页>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
1995My 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;
}
边栏推荐
- Heavyweight! The domestic IDE is released and developed by Alibaba. It is completely open source! (high performance + high customization)
- HMS Core机器学习服务实现同声传译,支持中英文互译和多种音色语音播报
- Async await to achieve sleep waiting effect
- [world history] Episode 1: people in the Stone Age
- 合宙Air32F103CBT6开发板上手报告
- PubSub JS library realizes "cross component" data transfer
- HMS core machine learning service realizes simultaneous interpretation, supports Chinese-English translation and multiple voice broadcast
- Power automatic test system nsat-8000, accurate, high-speed and reliable power test equipment
- 【深度学习】多任务学习 多个数据集 数据集漏标
- One time summary: 64 common terms for data analysis!
猜你喜欢

oracle数据库常用的函数总结

Kubernetes 理解kubectl/调试

New good friend Pinia, leading the new era of state management

Partager les points techniques de code et l'utilisation de logiciels pour la communication Multi - clients socket que vous utilisez habituellement

重磅!国产 IDE 发布,由阿里研发,完全开源!(高性能+高定制性)

Build a minimalist gb28181 gatekeeper and gateway server, establish AI reasoning and 3D service scenarios, and then open source code (I)

To make pytorch faster, you need to master these 17 methods

SPARQL learning notes of query, an rrdf query language

QQ情话糖果情话内容获取并保存

Stream竟然还有应用进阶学习?作为程序员的你知道吗
随机推荐
NBD Network Block Device
[world history] Episode II: Dawn of civilization
Two common ways for orcale to clear table data
Is it safe to open an online stock account? Who knows
How to choose a technology stack for web applications in 2022
[Ocean University of China] information sharing for the first and second examinations of postgraduate entrance examination
Does stream even have application advanced learning? As a programmer, you know what
Disable scrolling in the iPhone web app- Disable scrolling in an iPhone web application?
【HBZ分享】LockSupport的使用
14 -- validate palindrome string II
Clinical chemistry | zhangjianzhong / Xu Jian develop single cell precision diagnosis and treatment technology for Helicobacter pylori
How to cut the size of a moving picture? Try this online photo cropping tool
Which is better and safer, GF easy gold rush or flush
重磅!国产 IDE 发布,由阿里研发,完全开源!(高性能+高定制性)
挖财是正规的吗?股票开户安全吗?
QT file reading -qfile
15 -- 最接近原点的 K 个点
How to combine multiple motion graphs into a GIF? Generate GIF animation pictures in three steps
Differences between member variables and local variables
Build a minimalist gb28181 gatekeeper and gateway server, establish AI reasoning and 3D service scenarios, and then open source code (I)