zerojudge a010. 因數分解

 zerojudge a010. 因數分解


可惜沒有辦法畫好圖,不然會更好理解解法


解法大全:

建表(真的只能建表因為有次方問題,無法直接印)


1.直接存質數

        輸出時判斷該數字出現幾次

        可以連續的判斷

  如:2 2 2 2 2 5

                      | | 

        if(arr[i]==arr[i+1])

			index++;

  或分開的判斷

  如:2 2 2 2 2 5

                  |        |


         if(arr[i]==arr[i+index])      

                          index++;     

        執行資訊:AC (5ms, 344KB)  

2.存各個數字頻率

        執行資訊:AC (7ms, 4.1MB) 

3.存質數頻率搭配質數表

            先建質數表

            存質數頻率

  執行資訊:未知


註:


        for(LLI i=2;i<=n;i++)
	{
		if(n%i==0)
		{
			arr[cnt++]=i;
			n/=i;
			i--;//減去1後來又加1,校正,I才沒有增加
		}
	}

Comments

Popular posts from this blog

zerojudge c561. Bert 愛搗蛋

zerojudge d122. Oh! My Zero!!