結果

問題 No.300 平方数
ユーザー 37zigen37zigen
提出日時 2016-05-18 18:40:06
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,766 bytes
コンパイル時間 2,265 ms
コンパイル使用メモリ 79,292 KB
実行使用メモリ 47,792 KB
最終ジャッジ日時 2024-04-15 22:55:46
合計ジャッジ時間 12,054 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 188 ms
47,380 KB
testcase_01 AC 188 ms
47,456 KB
testcase_02 AC 188 ms
47,624 KB
testcase_03 AC 189 ms
47,316 KB
testcase_04 AC 171 ms
46,436 KB
testcase_05 AC 188 ms
47,648 KB
testcase_06 AC 188 ms
47,792 KB
testcase_07 AC 190 ms
47,420 KB
testcase_08 AC 184 ms
47,460 KB
testcase_09 AC 185 ms
47,504 KB
testcase_10 AC 185 ms
47,184 KB
testcase_11 AC 184 ms
47,512 KB
testcase_12 AC 187 ms
47,456 KB
testcase_13 AC 189 ms
47,172 KB
testcase_14 AC 183 ms
47,672 KB
testcase_15 AC 187 ms
47,208 KB
testcase_16 AC 188 ms
47,580 KB
testcase_17 AC 189 ms
47,208 KB
testcase_18 AC 185 ms
47,352 KB
testcase_19 AC 168 ms
46,348 KB
testcase_20 AC 188 ms
47,528 KB
testcase_21 AC 182 ms
47,360 KB
testcase_22 AC 183 ms
47,544 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 167 ms
46,560 KB
testcase_39 AC 186 ms
47,684 KB
testcase_40 AC 165 ms
46,588 KB
testcase_41 WA -
testcase_42 AC 180 ms
47,644 KB
testcase_43 AC 180 ms
47,348 KB
testcase_44 AC 181 ms
47,232 KB
testcase_45 AC 184 ms
47,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		new Main().solve();
	}
	void solve(){
		Scanner sc=new Scanner(System.in);
		long x=sc.nextLong();
		Prime p=new Prime();
		ArrayList<Integer> ps=p.primeList(1_000_000);
		ArrayList<Factor> fs=p.primeFactorF(ps, x);
		long y=1;
		for(Factor f:fs){
			if(f.exp%2==0){
				continue;
			}else{
				y*=f.base;
			}
		}
		System.out.println(y);
	}
	class Prime{
		boolean[] isPrimeArray(int max){
			boolean[] isPrime=new boolean[max+1];
			Arrays.fill(isPrime, true);
			isPrime[0]=isPrime[1]=false;
			for(int i=2;i*i<=max;i++){
				if(isPrime[i]){
					for(int j=2;j*i<=max;j++){
						isPrime[j*i]=false;
					}
				}
			}
			return isPrime;
		}
		/*
		 * max以下の素数のリストを返す
		 */
		ArrayList<Integer> primeList(int max){
			boolean[] isPrime=isPrimeArray(max);
			ArrayList<Integer> primeList=new ArrayList<Integer>();
			for(int i=2;i<=max;i++){
				if(isPrime[i]){
					primeList.add(i);
				}
			}
			return primeList;
		}
		/*
		 * numをprimeListの素数をもとに素因数分解し、因数を
		 * ArrayList<Factor>の形で返す。
		 * primeListにはnumの平方根以下の素数が含まれていなければならない。
		 * 
		 */
		ArrayList<Factor> primeFactorF(ArrayList<Integer> primeList,long num){
			ArrayList<Factor> ret=new ArrayList<Factor>();
			for(int p:primeList){
				int exp=0;
				while(num%p==0){
					num/=p;
					exp++;
				}
				if(exp>0)ret.add(new Factor(p,exp));
			}
			if(num>1)ret.add(new Factor((int)num,1));
			return ret;
		}
	}
	class Factor{
		int base,exp;
		Factor(int base,int exp){
			this.base=base;
			this.exp=exp;
		}
	}
}
0