HITOJ Prime Land 1069 (求质因子) 好题
来源:互联网 发布:php正则验证身份证 编辑:程序博客网 时间:2024/05/20 08:44
Prime Land
Submitted : 238, Accepted : 133
Everybody in the Prime Land is using a prime base number system. In this system, each positive integer x is represented as follows: Let {pi}i=0 denote the increasing sequence of all prime numbers. We know that x > 1 can be represented in only one way in the form of product of powers of prime factors. This implies that there is an integer kx and uniquely determined integers ekx, ekx-1, ..., e1, e0, (ekx > 0), that x = p(ekx,kx)*p(ekx-1,kx-1)*...*p(e1,1)*p(e0,0). The sequence
(ekx, ekx-1, ... ,e1, e0)
is considered to be the representation of x in prime base number system.
It is really true that all numerical calculations in prime base number system can seem to us a little bit unusual, or even hard. In fact, the children in Prime Land learn to add to subtract numbers several years. On the other hand, multiplication and division is very simple.
Recently, somebody has returned from a holiday in the Computer Land where small smart things called computers have been used. It has turned out that they could be used to make addition and subtraction in prime base number system much easier. It has been decided to make an experiment and let a computer to do the operation ``minus one''.
Help people in the Prime Land and write a corresponding program.
For practical reasons we will write here the prime base representation as a sequence of such pi and ei from the prime base representation above for which ei > 0. We will keep decreasing order with regard to pi.
Input
The input consists of lines (at least one) each of which except the last contains prime base representation of just one positive integer greater than 2 and less or equal 32767. All numbers in the line are separated by one space. The last line contains number 0.
Output
The output contains one line for each but the last line of the input. If x is a positive integer contained in a line of the input, the line in the output will contain x - 1 in prime base representation. All numbers in the line are separated by one space. There is no line in the output corresponding to the last ``null'' line of the input.
Sample Input
17 15 1 2 1509 1 59 10
Sample Output
2 43 213 1 11 1 7 1 5 1 3 1 2 1
//题意:输入是一行数字,并且数字是两两成对的,第一个表示的是质因子,第二个表示的是这个质因子的次数。通过这些可以得到一个确定的值为n,现在想让你计算(n-1)的质因子,按照输入的方式将其表示出来。
//思路;
直接模拟
#include<stdio.h>#include<string.h>#include<algorithm>#define N 1000010using namespace std;struct zz{int p;int e;}q[110];bool pp[210];int p[210];int getp(){int i,j,k=0;for(i=2;i<=200;i++){if(!pp[i]){p[k++]=i;for(j=i*i;j<=200;j+=i)pp[j]=true;}}}void solve(int n){int i,num=0;for(i=0;p[i]*p[i]<=n;i++){if(n%p[i]==0){n/=p[i];q[num].p=p[i];q[num].e=1;while(n%p[i]==0){n/=p[i];q[num].e=q[num].e+1;}num++;}if(n==1)break;}if(n>1){q[num].e=1;q[num].p=n;num++;}for(i=num-1;i>0;i--)printf("%d %d ",q[i].p,q[i].e);printf("%d %d\n",q[0].p,q[0].e);}int main(){getp();int n,a,b,i,j,k,m;char c;while(scanf("%d",&n),n){k=0;q[k].p=n;scanf("%d",&a);q[k].e=a;k++;m=1;while(1){scanf("%c",&c);if(c=='\n')break;scanf("%d %d",&a,&b);q[k].p=a;q[k].e=b;k++;}for(i=0;i<k;i++){for(j=1;j<=q[i].e;j++)m*=q[i].p;}solve(m-1);}return 0;}
- HITOJ Prime Land 1069 (求质因子) 好题
- poj 1365 Prime Land (质因子分解)
- POJ 1365 Prime Land(素因子分解)
- POJ_1365_Prime Land(分解质因子)
- POJ 1811 Prime Test(判断大素数&求最小质因子)
- Prime Land
- Prime Land
- Prime Land
- Prime Land
- Prime Land
- POJ 1365 Prime Land(分解质因数)
- POJ 1365 Prime Land(接收数据)
- POJ 1365 Prime Land(质因数分解)
- 快速求质因子(一定程度上,比辗转相除好得多)
- (hdu step 2.1.3)Largest prime factor(求一个数的最大质因子的位置)
- PAT (Advanced Level) 1059. Prime Factors (25) 求所有质因子
- UVA 10780-Again Prime? No Time. (数学-质因子)
- The Factor(数论规律题+求质因子)
- 常用DOS命令(三)--RD命令
- 单例模式
- Android开发之第三方跳转
- Swift的String类型转换如何实现?
- 推荐C++ Primer 第五版
- HITOJ Prime Land 1069 (求质因子) 好题
- 一步一步学写makefile
- R中的SQL包--sqldf
- Android_(自定义view_3)
- Confluence5.8.10安装、破解、设置
- vs2005 + DriverStudio3.2 修改方法
- vs2003一查找就卡死了
- 【可持久化线段树】poj 2104 静态区间第k大
- js unicode编码与解码