結果

問題 No.1274 楽しい格子点
ユーザー SSRS
提出日時 2020-10-30 22:06:55
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 923 bytes
コンパイル時間 1,285 ms
コンパイル使用メモリ 168,192 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-22 18:37:17
合計ジャッジ時間 2,547 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 57
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
double p(int x){
  double ans = 1;
  for (int i = 0; i < x; i++){
    ans /= x;
  }
  return ans;
}
int main(){
  cout << fixed << setprecision(10);
  long long A, B;
  cin >> A >> B;
  if (A == 0 && B == 0){
    cout << p(2) << endl;
    return 0;
  }
  A = abs(A);
  B = abs(B);
  long long g = __gcd(A, B);
  A /= g;
  B /= g;
  if (A % 2 == 1 && B % 2 == 1){
    double ans = 0;
    for (int i = 1; i <= 100; i++){
      for (int j = 1; j <= 100; j++){
        if ((i - 1) % g == 0 && (j - 1) % g == 0){
          if (abs(i - j) % (g * 2) == 0){
            ans += p(i + j);
          }
        }
      }
    }
    cout << ans << endl;
  } else {
    double ans = 0;
    for (int i = 1; i <= 100; i++){
      for (int j = 1; j <= 100; j++){
        if ((i - 1) % g == 0 && (j - 1) % g == 0){
          ans += p(i + j);
        }
      }
    }
    cout << ans << endl;
  }
}
0