結果

問題 No.781 円周上の格子点の数え上げ
ユーザー kps
提出日時 2021-12-06 23:37:29
言語 Java
(openjdk 23)
結果
AC  
実行時間 304 ms / 2,000 ms
コード長 913 bytes
コンパイル時間 1,822 ms
コンパイル使用メモリ 74,516 KB
実行使用メモリ 96,132 KB
最終ジャッジ日時 2024-07-07 09:49:57
合計ジャッジ時間 6,077 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    //原点を中心とする半径maxR以下の円それぞれの円周上にある格子点を数え上げるプログラム
    	//計算量:O(maxR*maxR)
    	int X=sc.nextInt(),Y=sc.nextInt();
    	int maxR=(int)Math.sqrt(Y);
    	int counter[]=new int[Y+1];
    	//counter[i]:半径√iの円の円周上にある格子点の数,ex:counter[4]は半径2の円の答え
    	
    	for(int x=-maxR;x<=maxR;x++) {
    		for(int y=-maxR;y<=maxR;y++) {
    			//(x,y)が半径Rの円の円周上にある⇔x^2+y^2=R^2
    			if(x*x+y*y>Y)continue;
    			counter[x*x+y*y]++;
    			
    		}
    	}
    	int ans=0;
    	for(int i=X;i<=Y;i++) {
    		ans=Math.max(ans, counter[i]);
    		//System.out.println("半径√iの円の答え:"+counter[i]);
    	}
    	System.out.println(ans);
  }
}
0