結果

問題 No.87 Advent Calendar Problem
ユーザー 👑 CleyL
提出日時 2022-09-21 16:00:11
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 650 bytes
コンパイル時間 575 ms
コンパイル使用メモリ 67,164 KB
最終ジャッジ日時 2025-02-07 13:21:43
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
bool uru(int n){
  if(n%400 == 0)return true;
  else if(n%100 == 0)return false;
  else if(n%4 == 0)return true;
  return false;
}
int main(){
  long long n;cin>>n;
  int nw = 0;
  long long ans = 0;
  for(int i = 2015; min(2015+2800LL,n+1) > i; i++){
    if(uru(i))nw += 2;
    else nw += 1;
    nw %= 7;
    if(!nw)ans++;
  }
  if(2014+2800 < n){
    long long x = (n-2014)/2800;
    ans = ans*x;
    nw = 0;
    for(int i = 0; (n-2014)%2800 > i; i++){
      if(uru(2015+i))nw+=2;
      else nw += 1;
      nw %= 7;
      if(!nw)ans++;
    }
    cout << ans << endl;
  }else{
    cout << ans << endl;
  }
}
0