結果

問題 No.300 平方数
ユーザー 37zigen37zigen
提出日時 2016-05-18 18:43:11
言語 Java21
(openjdk 21)
結果
AC  
実行時間 188 ms / 1,000 ms
コード長 1,764 bytes
コンパイル時間 2,366 ms
コンパイル使用メモリ 78,768 KB
実行使用メモリ 47,768 KB
最終ジャッジ日時 2024-04-15 22:56:00
合計ジャッジ時間 11,684 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 182 ms
47,452 KB
testcase_01 AC 164 ms
46,676 KB
testcase_02 AC 184 ms
47,248 KB
testcase_03 AC 165 ms
46,280 KB
testcase_04 AC 182 ms
47,464 KB
testcase_05 AC 179 ms
47,612 KB
testcase_06 AC 164 ms
46,340 KB
testcase_07 AC 162 ms
46,432 KB
testcase_08 AC 177 ms
47,160 KB
testcase_09 AC 163 ms
46,532 KB
testcase_10 AC 164 ms
46,532 KB
testcase_11 AC 182 ms
47,588 KB
testcase_12 AC 180 ms
47,504 KB
testcase_13 AC 184 ms
47,596 KB
testcase_14 AC 168 ms
46,312 KB
testcase_15 AC 188 ms
46,500 KB
testcase_16 AC 178 ms
47,444 KB
testcase_17 AC 179 ms
47,588 KB
testcase_18 AC 171 ms
46,388 KB
testcase_19 AC 163 ms
46,500 KB
testcase_20 AC 167 ms
46,952 KB
testcase_21 AC 186 ms
47,292 KB
testcase_22 AC 185 ms
47,312 KB
testcase_23 AC 169 ms
46,780 KB
testcase_24 AC 180 ms
47,244 KB
testcase_25 AC 185 ms
47,384 KB
testcase_26 AC 180 ms
47,724 KB
testcase_27 AC 180 ms
47,432 KB
testcase_28 AC 177 ms
47,192 KB
testcase_29 AC 177 ms
47,220 KB
testcase_30 AC 179 ms
47,360 KB
testcase_31 AC 178 ms
47,604 KB
testcase_32 AC 178 ms
47,716 KB
testcase_33 AC 175 ms
47,296 KB
testcase_34 AC 179 ms
47,768 KB
testcase_35 AC 181 ms
47,420 KB
testcase_36 AC 179 ms
47,104 KB
testcase_37 AC 181 ms
47,492 KB
testcase_38 AC 179 ms
47,424 KB
testcase_39 AC 163 ms
46,688 KB
testcase_40 AC 175 ms
47,036 KB
testcase_41 AC 181 ms
47,184 KB
testcase_42 AC 181 ms
47,576 KB
testcase_43 AC 163 ms
46,532 KB
testcase_44 AC 179 ms
47,612 KB
testcase_45 AC 183 ms
47,184 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(num,1));
			return ret;
		}
	}
	class Factor{
		long base,exp;
		Factor(long base,long exp){
			this.base=base;
			this.exp=exp;
		}
	}
}
0