結果

問題 No.781 円周上の格子点の数え上げ
ユーザー akakimidoriakakimidori
提出日時 2019-01-11 21:56:37
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 870 bytes
コンパイル時間 1,571 ms
コンパイル使用メモリ 29,684 KB
実行使用メモリ 40,924 KB
最終ジャッジ日時 2023-08-20 05:52:05
合計ジャッジ時間 3,352 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 0 ms
4,380 KB
testcase_04 AC 0 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 121 ms
40,924 KB
testcase_09 AC 120 ms
40,804 KB
testcase_10 AC 0 ms
4,380 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 128 ms
40,868 KB
testcase_13 AC 130 ms
40,864 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 72 ms
24,896 KB
testcase_18 AC 68 ms
24,956 KB
testcase_19 AC 68 ms
25,696 KB
testcase_20 AC 67 ms
25,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>

#define MAX(a,b) ((a)>(b)?(a):(b))

typedef struct farey{
  int a,b,c,d;
} farey;

void run(void){
  int x,y;
  scanf("%d%d",&x,&y);
  int *cnt=(int *)calloc(y+1,sizeof(int));
  int k;
  for(k=1;k*k<=y;k++) cnt[k*k]+=4;
  for(k=1;2*k*k<=y;k++) cnt[2*k*k]+=4;
  farey stack[32];
  int top=0;
  stack[top++]=(farey){0,1,1,1};
  while(top>0){
    farey f=stack[--top];
    int p=f.a+f.c;
    int q=f.b+f.d;
    if(p*p+q*q>y) continue;
    for(k=1;k*k*(p*p+q*q)<=y;k++){
      cnt[k*k*(p*p+q*q)]+=8;
    }
    if(f.b<=f.d){
      stack[top++]=(farey){f.a,f.b,p,q};
      stack[top++]=(farey){p,q,f.c,f.d};
    } else {
      stack[top++]=(farey){p,q,f.c,f.d};
      stack[top++]=(farey){f.a,f.b,p,q};
    }
  }
  int max=cnt[x];
  for(k=x+1;k<=y;k++) max=MAX(max,cnt[k]);
  printf("%d\n",max);
}

int main(void){
  run();
  return 0;
}
0