質因數分解

來源:互聯網
上載者:User

標籤:style   blog   io   color   os   for   sp   div   log   

 1 //質因數分解 2 #include<cstdio> 3 #include<cstdlib> 4 #include<cstring> 5 #include<iostream> 6 #include<algorithm> 7 #include<queue> 8 #include<cmath> 9 using namespace std;10 int top=0,num[10000],time[10000];11 void fj(int n)12 {13     top=0;14     memset(num,0,sizeof(num));15     memset(time,0,sizeof(time));16     for(int i=2;i<=sqrt(n);i++)17     {18         if(n%i==0)19         { 20             top++;21             n/=i;22             num[top]=i;23             time[top]++;24             while(n%i==0)25             {26                 n/=i;27                 time[top]++;28             }29         }30     }31     if(n>1) {32         top++;33         num[top]=n;34         time[top]++;35     }36 }37 int main()38 {39     freopen("1.in","r",stdin);40     freopen("1.out","w",stdout);41     int n;42     cin>>n;43     fj(n);44     for(int i=1;i<=top;i++)45     {46         cout<<num[i]<<" "<<time[i]<<endl;47     }48     return 0;49 } 

質因數分解就是找到第一個非1因數連除直到不能整除為止再找下一個。

 

質因數分解

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.