poj1365---素数打表和质因子分解
来源:互联网 发布:数据采集传输仪 编辑:程序博客网 时间:2024/05/22 17:50
北京大学ACM/ICPC竞赛训练暑期课面向全球招生,欲报名从速!
Language:
Prime Land
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 3302 Accepted: 1507
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 ekx, ekx-1, ..., e1, e0, (ekx > 0), that 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.
(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
Source
Central Europe 1997
最近发现poj题好难过,还是自己太水,这道水题还是参考别人代码的,而且交了无数遍,实在水的一b,唉-----
最近发现poj题好难过,还是自己太水,这道水题还是参考别人代码的,而且交了无数遍,实在水的一b,唉-----
#include <iostream>#include <string.h>#include <stdio.h>#include <cmath>using namespace std;const int maxn=40000;int a[maxn],su[maxn],s1[maxn],i,j;int main(){ memset(a,1,sizeof(a)); a[0]=0; a[1]=0; //int num=0; for(i=2; i<=maxn; i++) { if(a[i]) { for(j=i+i; j<=maxn; j=j+i) { a[j]=0; } //su[num++]=i; } } //int p[maxn],e[maxn]; // int flag=0; int count=0,k,s,i; int ans; char dis[10000]; while(gets(dis)) { if(dis[0]=='0') break; int len=strlen(dis); for( i=0,ans=1; i<len; ) { k=0; s=0; while(dis[i]!=' ') { k=k*10+(dis[i]-'0'); i++; } i++; while(dis[i]!=' ' && i<len) { s=s*10+(dis[i]-'0'); i++; } i++; ans=ans*(int)pow((double)k,(double)s); } //cout<<k<<" "<<s; //cout<<a[7]; ans--; count=0; int sum=0; while(ans!=1) { for(i=ans; ; i--) { //cout<<"1"; if(a[i]&&ans%i==0) break; } s1[count++]=i; sum=0; while(ans%i==0) { ans/=i; sum++; } s1[count++]=sum; } printf("%d",s1[0]); for(i=1; i<count; i++) printf(" %d",s1[i]); printf("\n"); } return 0;}
0 0
- poj1365---素数打表和质因子分解
- 素数打表解决质因子分解
- POJ1365 Prime Land【质因数分解】【素数】【水题】
- 打素数表找因子
- 素数打表,质因数分解
- hdu-1164涮素数+质因子分解
- HDU 6069 素数筛+分解质因子
- miller_rabin素数判断和pollard_rho的素数因子分解算法
- HDU2521 反素数【因子数量+打表】
- Ural1055(素数打表+分解质因数)
- 1139: 质数分解 素数打表 水题
- 关于整数的质因子分解和筛素数的分析
- Pairs Forming LCM 素数筛和素因子分解
- 大素数测试和大数素因子分解
- HDU 1333 分解素数因子
- Codeforces-546D Soldier and Number Game 【质因子分解+打表+DP】
- 筛法求素数+分解质因子+欧拉函数+求约数
- POJ1811 miller-rabin素数测试pollard-rho质因子分解
- Android事件分发完全解析之为什么是她
- Android事件分发完全解析之事件从何而来
- 这代码哪里出了错误,要如何修改呢?
- Asp.Net页面生命周期
- Android自定义软键盘的实现
- poj1365---素数打表和质因子分解
- 第十三周 项目四--点、圆的关系(1~4)
- 蚂蚁流浪记
- Java关键字final、static使用总结(精)
- NFS(Network File System) 服务的配置与应用
- J2SE之面向对象——再看你一眼
- ViewPager+Fragment取消预加载(延迟加载)
- [20150428][Android第一个程序][拨号器]
- poj2987--Firing(最大权闭合图)