Prime Land
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 2736 | Accepted: 1291 |
Description
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,1,2,... 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 e
kx, e
kx-1, ..., e
1, e
0, (e
kx > 0), that
The sequence
(e kx, e kx-1, ... ,e 1, e 0)
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.
(e kx, e kx-1, ... ,e 1, e 0)
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 1 5 1 2 1 509 1 59 1 0
Sample Output
2 4 3 2 13 1 11 1 7 1 5 1 3 1 2 1 题意:异常EGGS PAIN ,给你一个X的质因子分解的形式,前一个是素因子,后一个是素因子的幂的形式,然后让你求出X-1的素因子分解的形式,降序输出。。 注意:输入要用字符串的形式输进去然后转成整形- -。。。 样例解释: 17 1 代表 X=17^1 X-1=16=2^4, 5 1 2 1 X=5^1*2^1=10 X-1=9=3^2 不知道为什么用C++不是TLE- - 竟然RE了5次,然后自己再测数据的时候又赶脚是快速幂写挫了,不过后来改成C的输入输出 竟然A了。。。。。。。#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; const int MAXN=33000; char ss[200]; bool is_prime[MAXN]; int prime[3600],p[500],num[500],a[200]; int ans,co; long long power(long long a,long long b)//快速幂部分 { long long ans = 1; while(b>0) { if(b&1) { ans = ans*a; } b>>=1; a = a*a; } return ans; } void dabiao()//筛法部分 { is_prime[0]=is_prime[1]=1; int i; int k=0; for(i=2;i<MAXN;i++) { is_prime[i]=0; } for(i=2;i<MAXN;i++) { if(is_prime[i]!=0) { continue; } for(int j=i*i;j<MAXN;j+=i) { is_prime[j]=1; } } for(i=2;i<MAXN;i++) { if(is_prime[i]==0) { prime[k++]=i; } } } void get_factor(long long t) //对t进行质因式分解,euler函数部分 { int i; co=0; memset(num,0,sizeof(num)); //用来标记因子的个数 for(i=0;t!=1;i++) if(t%prime[i]==0) { p[co]=prime[i]; num[co]++; t/=prime[i]; while(t%prime[i]==0) { num[co]++; t/=prime[i]; } co++; } } int main() { int i,j,len; long long sum; dabiao(); while(gets(ss)) { if(ss[0]=='0') break; memset(a,0,sizeof(a)); len=strlen(ss); for(i=0,j=0;i<len;i++)//字符串简单处理部分。。。 { if(ss[i]!=' ') a[j]=10*a[j]+(ss[i]-'0'); else j++; } sum=1; for(i=0;i<j;i+=2) sum*=power(a[i],a[i+1]); sum--; get_factor(sum); for(i=co-1;i>=0;i--) //降序输出 printf("%d %d ",p[i],num[i]); printf("\n"); } return 0; }