U E D R , A S I H C RSS

Factorial Factors/이동현

n! 2 <= k <= n 인 k의 인수를 구하는 방법과,
k .

n fac . (ex.fac8 8 3 .)
16 16 = 8x2 fac16 = fac8+1 = 4 .
fac8 .

k 통하 . . ^^


~cpp 
import java.util.*;
import java.math.*;

public class FactorialFactors2 {
	final int CASE_N = 1000000;	//테트할  
	int fac[] = new int[CASE_N+1];	//
	ArrayList<Integer> prime  = new ArrayList<Integer>();
	
	boolean isPrime(int num){
		for(int k=0;k<prime.size();k++){
			if(num%prime.get(k)==0)
				return false;		
		}		
		return true;
	}	
	
	void printResult(){
		int total=0;
		for(int i=2;i<=CASE_N; i++)
			total+=fac[i];
		System.out.println(total);
	}
	
	void run(){
		long time = System.currentTimeMillis();
		prime.add(2);
		fac[2] = 1;
		int sqrt = (int)Math.sqrt(CASE_N);
		//n!  2    3~n     .
		for(int i=3;i<=CASE_N;i++){
			int num = i;
			//num    .
			for(int j=2; num!=1;){
				if(num%j == 0){
					num = num/j;
					fac[i]++;
					fac[i]+=fac[num];					
					break;
				}
				else
					j++;	
				//7       .
				if (j == 7 && isPrime(num) == true) {
					fac[i]++;
					if (num <= sqrt) //    sqrt    .
						prime.add(num);
					break;
				}
			}			
		}
		printResult();
		System.out.print(System.currentTimeMillis()-time);	
	}
	public static void main(String[] args) {
		new FactorialFactors2().run();
	}
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:15
Processing time 0.0110 sec