nyist 70 階乘因式分解(二)

來源:互聯網
上載者:User

標籤:blog   http   os   io   strong   資料   for   ar   

階乘因式分解(二)時間限制:3000 ms  |  記憶體限制:65535 KB難度:3 
描述

給定兩個數n,m,其中m是一個素數。

將n(0<=n<=2^31)的階乘分解質因數,求其中有多少個m。

註:^為求冪符號。

 

 

 
輸入
第一行是一個整數s(0<s<=100),表示測試資料的組數
隨後的s行, 每行有兩個整數n,m。 
輸出
輸出m的個數
範例輸入
3100 516 21000000000  13
範例輸出
241583333329





#include <stdio.h>
int main( )
{
int count,n,m,i,ii,t;

scanf("%d",&t);
while(t--)
{
count=0;
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
{ ii=i ;
if(ii%m==0) // 逐個 檢驗
{
count++; // +1
ii=ii/m; // 新ii 是否 含m的某次方

while(ii%m==0) // m的某次方
{ count++; ii=ii/m; } //
}


}
printf("%d",count);
}

}


***************************************

 

 


#include <iostream>
using namespace std;
int main()
{
int m,n,k,s,sum;
cin >> s;
while(s--)
{
sum=0;
cin >> n >> m; //m是素數
while(n)
{
k=n/m;
sum+=k;
n=k;
}
cout << sum << endl;
}
}

 

***************************************

 

#include<stdio.h>

int main()
{
int s;
long long n,m,ans;

scanf("%d",&s);
while(s--)
{
scanf("%lld%lld",&n,&m);
ans=0;
while(n>=m)
{
ans+=n/m;
n/=m;
}
printf("%lld\n",ans);
}
return 0;
}


*********************88888

 

 

這裡好幾個題全是調用這個式子,不過為啥呢?這個式子分析不懂,高手給個回複吧!
cin>>a>>b;
k=0;
do
{
a/=b;
k+=a;
}while(a);
cout<<k<<endl;

 

 

 


*********************************8********************************************************

 

#include<stdio.h>
main()
{
int N,m,s,n;
scanf("%d",&N);
while(N--)
{ s=0;
scanf("%d%d",&n,&m);
do { n/=m ;
s+=n ; }
while(n) ;

printf("%d\n",s);
}
}

 


***************************88

****************************************

 

 

#include<stdio.h>
main()
{
int N,m,s,n;
scanf("%d",&N);
while(N--)
{ s=0;
scanf("%d%d",&n,&m);
while(n)
{ n/=m ;
s+=n ; }


printf("%d\n",s);
}
}

 

***************************

#include<stdio.h>

int main()
{
int N,n,m;
scanf("%d",&N);
while (N--)
{
scanf("%d%d",&n,&m);
int ans;
ans=0;
while(n>=m)
{
ans+=n/m;
n/=m;
}
printf("%d\n",ans);
}
return 0;
}


********************************

 

 

/*
http://www.cnblogs.com/liwenxin/archive/2011/04/12/jiechengyinshifenjie.html
*/


#include <iostream>
using namespace std;
int jc(int n,int m)
{
int sum=0;
while(n)

{

sum+=n/m;
n/=m;
}

return sum;
}


int main()
{
int s;
cin>>s;
while(s--)
{
int n,m;
cin>>n>>m;
cout<<jc(n,m)<<endl;
}
return 0;
}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.