結果

問題 No.376 立方体のN等分 (2)
ユーザー 37zigen37zigen
提出日時 2016-06-04 23:50:43
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,156 ms / 5,000 ms
コード長 2,403 bytes
コンパイル時間 2,305 ms
コンパイル使用メモリ 76,952 KB
実行使用メモリ 57,116 KB
最終ジャッジ日時 2023-08-06 18:51:15
合計ジャッジ時間 16,998 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 151 ms
56,868 KB
testcase_01 AC 150 ms
56,532 KB
testcase_02 AC 284 ms
56,452 KB
testcase_03 AC 262 ms
56,752 KB
testcase_04 AC 1,156 ms
56,420 KB
testcase_05 AC 149 ms
56,864 KB
testcase_06 AC 150 ms
56,572 KB
testcase_07 AC 150 ms
56,616 KB
testcase_08 AC 176 ms
56,612 KB
testcase_09 AC 185 ms
56,728 KB
testcase_10 AC 181 ms
56,452 KB
testcase_11 AC 410 ms
56,848 KB
testcase_12 AC 292 ms
56,768 KB
testcase_13 AC 376 ms
56,664 KB
testcase_14 AC 470 ms
56,528 KB
testcase_15 AC 341 ms
56,816 KB
testcase_16 AC 184 ms
56,840 KB
testcase_17 AC 238 ms
56,656 KB
testcase_18 AC 372 ms
56,568 KB
testcase_19 AC 281 ms
56,808 KB
testcase_20 AC 429 ms
56,448 KB
testcase_21 AC 187 ms
56,864 KB
testcase_22 AC 354 ms
56,608 KB
testcase_23 AC 188 ms
56,776 KB
testcase_24 AC 196 ms
56,636 KB
testcase_25 AC 161 ms
56,752 KB
testcase_26 AC 188 ms
56,652 KB
testcase_27 AC 530 ms
56,748 KB
testcase_28 AC 369 ms
56,748 KB
testcase_29 AC 754 ms
56,936 KB
testcase_30 AC 508 ms
56,560 KB
testcase_31 AC 326 ms
57,116 KB
testcase_32 AC 219 ms
56,884 KB
testcase_33 AC 152 ms
56,672 KB
testcase_34 AC 265 ms
56,772 KB
testcase_35 AC 642 ms
56,764 KB
testcase_36 AC 370 ms
56,776 KB
testcase_37 AC 370 ms
56,676 KB
testcase_38 AC 676 ms
56,560 KB
testcase_39 AC 304 ms
56,784 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 N=sc.nextLong();
//		Prime p=new Prime(N);
//		ArrayList<Factor> f=p.primeFactorF(N);
		long min=Long.MAX_VALUE;
		//10^11
		//10^3*10^5
		//i<j<N/(i*j)
		//i*i*j<N
		//i*j*j<N
		for(int i=(int)Math.cbrt(N);i>=1;i--){
			if(N%i==0){
				for(long j=(long)Math.sqrt(N/i);j>=1;j--){
					if(((N/i)%j==0)){
						min=Math.min(min, i-1+j-1+N/(i*j)-1);
						break;
					}
				}
			}
		}
		System.out.println(min+" "+(N-1));
	}
	class Prime{
		long n;
		ArrayList<Integer> ps=new ArrayList<Integer>();
		//n:素因数分解したい最大の数
		Prime(long n){
			this.n=n;
			ps=primeList((int)Math.sqrt(n));
		}
		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>の形で返す。1は含まれない。
		 * 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;
		}
		ArrayList<Factor> primeFactorF(long num){
			ArrayList<Factor> ret=new ArrayList<Factor>();
			for(int p:ps){
				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