結果

問題 No.375 立方体のN等分 (1)
ユーザー 37zigen37zigen
提出日時 2016-06-04 23:46:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 157 ms / 5,000 ms
コード長 2,401 bytes
コンパイル時間 2,558 ms
コンパイル使用メモリ 85,764 KB
実行使用メモリ 55,424 KB
最終ジャッジ日時 2024-04-20 02:05:12
合計ジャッジ時間 7,723 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
54,876 KB
testcase_01 AC 123 ms
54,960 KB
testcase_02 AC 127 ms
54,764 KB
testcase_03 AC 129 ms
54,756 KB
testcase_04 AC 121 ms
54,616 KB
testcase_05 AC 121 ms
54,588 KB
testcase_06 AC 129 ms
54,716 KB
testcase_07 AC 127 ms
54,792 KB
testcase_08 AC 132 ms
54,952 KB
testcase_09 AC 132 ms
54,768 KB
testcase_10 AC 144 ms
55,176 KB
testcase_11 AC 152 ms
55,136 KB
testcase_12 AC 139 ms
54,876 KB
testcase_13 AC 147 ms
55,168 KB
testcase_14 AC 119 ms
54,588 KB
testcase_15 AC 135 ms
54,880 KB
testcase_16 AC 140 ms
54,788 KB
testcase_17 AC 127 ms
54,848 KB
testcase_18 AC 133 ms
54,932 KB
testcase_19 AC 152 ms
55,040 KB
testcase_20 AC 141 ms
54,528 KB
testcase_21 AC 136 ms
55,212 KB
testcase_22 AC 134 ms
55,308 KB
testcase_23 AC 149 ms
54,912 KB
testcase_24 AC 131 ms
55,424 KB
testcase_25 AC 134 ms
55,108 KB
testcase_26 AC 132 ms
54,988 KB
testcase_27 AC 141 ms
55,020 KB
testcase_28 AC 135 ms
55,128 KB
testcase_29 AC 132 ms
55,212 KB
testcase_30 AC 157 ms
55,320 KB
testcase_31 AC 141 ms
54,888 KB
testcase_32 AC 142 ms
55,168 KB
testcase_33 AC 145 ms
54,740 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(int j=(int)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