2021牛客多校第八场

August 24, 2021 · 算法 · 29次阅读

E 签到

题目

求一个年份是不是质数闰年。

代码

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <cmath>

#define fo(ii, nn) for(int ii=1;ii<=nn;ii++)

using namespace std;
typedef unsigned long long ll;
typedef pair<int, int> pai;
const int N = 100000 + 10;
const int mod = 1e9 + 7;

inline bool read(int &num) {
    //quick read
    char in;
    bool IsN = false;
    in = getchar();
    if (in == EOF) return false;
    while (in != '-' && (in < '0' || in > '9')) in = getchar();
    if (in == '-') {
        IsN = true;
        num = 0;
    } else num = in - '0';
    while (in = getchar(), in >= '0' && in <= '9') { num *= 10, num += in - '0'; }
    if (IsN) num = -num;
    return true;
}

bool qu(ll k) {
    for (ll i = 2; i * i <= k; i++) {
        if (k % i == 0) return false;
    }
    return true;
}


void solve() {
    ll a;
    cin >> a;
    if (a % 4 == 0) {
        if (a % 100 == 0 && a % 400 != 0) {
            cout << "no" << endl;
        } else {
            if (!qu(a)) {
                cout << "no" << endl;
                return;
            }
            cout << "yes" << endl;
        }

    } else {
        cout << "no" << endl;
    }
}

int main() {
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

牛客多校

最后编辑于27天前

添加新评论