数学概念——J - 数论,质因数分解
生活随笔
收集整理的這篇文章主要介紹了
数学概念——J - 数论,质因数分解
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
J -?數(shù)論,質(zhì)因數(shù)分解 Time Limit:1000MS?????Memory Limit:32768KB?????64bit IO Format:%I64d & %I64u Submit?Status
We have been training for 45 days, and all guys must be tired.But , you are so lucky comparing with many excellent boys who have no chance to attend the Province-Final.?
Now, your task is relaxing yourself and making the last practice. I guess that at least there are 2 problems which are easier than this problem.?
what does this problem describe??
Give you a positive integer, please split it to some prime numbers, and you can got it through sample input and sample output.?
解題思路:
這個題目很簡單,但是要注意一個陷井,就是輸入一個數(shù)的時候,它的結(jié)束條件是負數(shù),一定要注意
程序代碼: #include <cstdio> #include <cstring> using namespace std; int b[66550]; int n; void p( ) {int m=n;while(1){for(int i=2;i<=n;i++ )if(m%i==0){b[i]++;m/=i;break;}if(m==1)break;}} int main() {int Case=0;while(scanf("%d",&n)==1&&n>0){if(Case>0) printf("\n");memset(b,0,sizeof(b));p();printf("Case %d.\n",++Case);for(int i=2;i<=n;i++)if(b[i]!=0)printf("%d %d ",i,b[i]);printf("\n");} } View Code
Description
Tomorrow is contest day, Are you all ready??We have been training for 45 days, and all guys must be tired.But , you are so lucky comparing with many excellent boys who have no chance to attend the Province-Final.?
Now, your task is relaxing yourself and making the last practice. I guess that at least there are 2 problems which are easier than this problem.?
what does this problem describe??
Give you a positive integer, please split it to some prime numbers, and you can got it through sample input and sample output.?
Input
Input file contains multiple test case, each case consists of a positive integer n(1<n<65536), one per line. a negative terminates the input, and it should not to be processed.Output
For each test case you should output its factor as sample output (prime factor must come forth ascending ), there is a blank line between outputs.Sample Input
60 12 -1Sample Output
Case 1. 2 2 3 1 5 1 Case 2. 2 2 3 1Hint
60=2^2*3^1*5^1解題思路:
這個題目很簡單,但是要注意一個陷井,就是輸入一個數(shù)的時候,它的結(jié)束條件是負數(shù),一定要注意
程序代碼: #include <cstdio> #include <cstring> using namespace std; int b[66550]; int n; void p( ) {int m=n;while(1){for(int i=2;i<=n;i++ )if(m%i==0){b[i]++;m/=i;break;}if(m==1)break;}} int main() {int Case=0;while(scanf("%d",&n)==1&&n>0){if(Case>0) printf("\n");memset(b,0,sizeof(b));p();printf("Case %d.\n",++Case);for(int i=2;i<=n;i++)if(b[i]!=0)printf("%d %d ",i,b[i]);printf("\n");} } View Code
?
轉(zhuǎn)載于:https://www.cnblogs.com/www-cnxcy-com/p/4750476.html
總結(jié)
以上是生活随笔為你收集整理的数学概念——J - 数论,质因数分解的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 简单的Flash GUI工具(Simpl
- 下一篇: UIAutomator输入中文