結果

問題 No.2271 平方根の13桁精度近似計算
ユーザー chro_96
提出日時 2023-04-15 00:21:51
言語 C
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 847 bytes
コンパイル時間 674 ms
コンパイル使用メモリ 30,464 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-10 15:16:25
合計ジャッジ時間 3,951 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int main () {
  long long n = 0LL;
  int e = 0;
  
  int res = 0;
  
  long long ans = -1LL;
  long long d = 1LL;
  
  long long tmp = 0LL;
  long long g[625][625] = {};
  int gcnt[25] = {};
  
  res = scanf("%lld", &n);
  res = scanf("%d", &e);
  
  while (e > 0) {
    d *= 5LL;
    e--;
  }
  
  if (n > 0LL) {
    n %= d;
  } else {
    n = (d-(-n)%d)%d;
  }
  
  for (int i = 0; i < 625; i++) {
    g[(i*i)%625][gcnt[(i*i)%625]] = (long long)i;
    gcnt[(i*i)%625]++;
  }
  
  while (ans < 0LL && tmp < d && tmp <= (1LL<<29LL)) {
    for (int i = 0; i < gcnt[(int)(n%625LL)]; i++) {
      long long tmp2 = tmp+g[(int)(n%625LL)][i];
      if ((tmp2*tmp2)%d == n) {
        ans = tmp2;
      }
    }
    tmp += 625LL;
  }
  
  if (ans < 0LL) {
    printf("NaN\n");
  } else {
    printf("%lld\n", ans);
  }
  
  return 0;
}
0