Editorial for Năm nhuận
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
\(\color{red}{\text{Spoiler Alert}_{{}_{{}^{{}^{v2.99}}}}}\)
\(\color{#008b8b}{\text{Hướng dẫn}}\)
- Năm \(n\) là năm nhuận khi mà (\(n\) chia hết cho \(400\)) hoặc (\(n\) chia hết cho \(4\) và \(n\) không chia hết cho \(100\))
\(\color{#008b8b}{\text{Độ phức tạp}}\)
-
Mỗi truy vấn mất \(O(1)\)
-
Có \(q\) truy vấn tất cả
\(\color{#008b8b}{\text{Code tham khảo }}\): Cài đặt
\(^{^{\color{purple}{\text{Độ phức tạp : }} O(q)\ \color{purple}{\text{thời gian}}\ ||\ O(1)\ \color{purple}{\text{bộ nhớ}}}}\)
C++
#include <iostream>
using namespace std;
int main()
{
int q;
cin >> q;
while (q-->0)
{
int n;
cin >> n;
cout << ((n % 4 == 0) && !(n % 100 == 0) || (n % 400 == 0) ? "YES" : "NO") << '\n';
}
return 0;
}
Comments