結果

問題 No.781 円周上の格子点の数え上げ
ユーザー akakimidoriakakimidori
提出日時 2019-01-11 21:56:37
言語 C
(gcc 11.2.0)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 870 bytes
コンパイル時間 407 ms
使用メモリ 41,016 KB
最終ジャッジ日時 2023-01-06 11:18:07
合計ジャッジ時間 2,405 ms
ジャッジサーバーID
(参考情報)
judge16 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 0 ms
3,116 KB
testcase_01 AC 1 ms
3,116 KB
testcase_02 AC 0 ms
3,116 KB
testcase_03 AC 0 ms
3,112 KB
testcase_04 AC 0 ms
3,116 KB
testcase_05 AC 1 ms
3,116 KB
testcase_06 AC 1 ms
3,116 KB
testcase_07 AC 1 ms
3,116 KB
testcase_08 AC 133 ms
40,908 KB
testcase_09 AC 136 ms
41,016 KB
testcase_10 AC 1 ms
3,116 KB
testcase_11 AC 1 ms
3,116 KB
testcase_12 AC 138 ms
40,916 KB
testcase_13 AC 141 ms
41,004 KB
testcase_14 AC 5 ms
4,168 KB
testcase_15 AC 1 ms
3,116 KB
testcase_16 AC 1 ms
3,116 KB
testcase_17 AC 71 ms
24,960 KB
testcase_18 AC 67 ms
25,004 KB
testcase_19 AC 72 ms
25,700 KB
testcase_20 AC 75 ms
25,792 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