[暑假集训--数论]poj1365 Prime Land

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.

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

给一个数n<32768的分解质因数的形式,把n-1分解质因数

n这么小直接暴力

我也不是很懂这题意义何在,可能是考察输入吧

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cstring>
 4 #define LL long long
 5 #define int long long
 6 using namespace std;
 7 inline LL read()
 8 {
 9     LL x=0,f=1;char ch=getchar();
10     while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
11     while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
12     return x*f;
13 }
14
15 bool mk[1000010];
16 int pp[1000010],len;
17 int p[1000010],q[1000100],len2;
18 int n,s,t;
19 inline void getp()
20 {
21     for (int i=2;i<=1000000;i++)
22     {
23         if (!mk[i])
24         {
25             pp[++len]=i;
26             for (int j=2*i;j<=1000000;j+=i)mk[j]=1;
27         }
28     }
29 }
30 inline int quickpow(int a,int b)
31 {
32     int ans=1;
33     while (b)
34     {
35         if (b&1)ans=ans*a;
36         a=a*a;
37         b>>=1;
38     }
39     return ans;
40 }
41 main()
42 {
43     getp();
44     while (~scanf("%lld",&s))
45     {
46         if (s==0)break;
47         scanf(" %lld",&t);
48         n=quickpow(s,t);
49         char c=getchar();
50         while (c!=‘\n‘&&c!=EOF)
51         {
52             scanf("%lld %lld",&s,&t);
53             n*=quickpow(s,t);
54             c=getchar();
55         }
56         n--;len2=0;
57         for (int i=1;i<=len;i++)
58         {
59             if ((LL)pp[i]*pp[i]>n)break;
60             if (n%pp[i]==0)
61             {
62                 p[++len2]=pp[i];q[len2]=0;
63                 while (n%pp[i]==0)n/=pp[i],q[len2]++;
64             }
65         }
66         if (n!=1||!len2)p[++len2]=n,q[len2]=1;
67         for (int i=len2;i>=1;i--)
68         {
69             printf("%lld %lld",p[i],q[i]);
70             if (i==1)puts("");else printf(" ");
71         }
72         if (c==EOF)break;
73     }
74 }

poj 1365

时间: 2024-10-12 10:22:26

[暑假集训--数论]poj1365 Prime Land的相关文章

poj1365 Prime Land

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 represe

POJ1365 Prime Land【质因数分解】【素数】【水题】

题目链接: http://poj.org/problem?id=1365 题目大意: 告诉你一个数的质因数x的全部底数pi和幂ei.输出x-1的质因数的全部底数和幂 解题思路: 这道题不难.可是题意特别不好理解.对于我这样的英文渣的人.愣是一个小时没看明确 关于题意举例说明吧 比如 509 1 59 1 x = 509^1 * 59^1 = 30031 x-1 = 30030 则答案 13 1 11 1 7 1 5 1 3 1 2 1 就是 x-1 = 13^1 * 11^1 * 7^1 * 5

[暑假集训--数论]poj2034 Anti-prime Sequences

Given a sequence of consecutive integers n,n+1,n+2,...,m, an anti-prime sequence is a rearrangement of these integers so that each adjacent pair of integers sums to a composite (non-prime) number. For example, if n = 1 and m = 10, one such anti-prime

[暑假集训--数论]poj2657 Comfort

Description A game-board consists of N fields placed around a circle. Fields are successively numbered from1 to N clockwise. In some fields there may be obstacles. Player starts on a field marked with number 1. His goal is to reach a given field mark

2017暑假集训前总结和规划

距离大一进来已经一年了啊,感觉还是啥也不会,哎,太差了,总结一下这一年都学了写什么吧! 大一寒假开始专题,刷过的有:dp,dfs和bfs,数论(gcd拓展gcd,欧拉定理等等,但是中国剩余定理没学,等复习的时候再学吧),并查集,最短路(bellman-fprd,dijkstra,floyd-warshall,spfa),最小生成树(prim,kruskal),线段树,二分三分 大一下学期有:拓扑排序,基础计算几何(直线线段相交,快速排除实验,跨立实验),矩阵快速幂,博弈基础(nim博弈,威佐夫博

暑假集训结束

暑假集训结束了!!! 说实话其实还是有些遗憾的,我没有和同学一起去诸暨集训,但是我还是很高兴,我的同学将试题都发给了我,以至于我没有落后太多,所以这里致谢机房其他4位大佬. 我重新翻了一下我的做题记录,虽然做题不多,但是至少每道题都有收益,于是想要总结一下. 6.16 期末考试告一段落 6.17 复习了并查集,知道了并查集记录链头和链长的方法P1196 6.18 继续研究DP,加深了树形DP,学习了悬线法,用此方法解决了以前乱搞的题 6.19 复习状压DP 6.20 pb学哥来讲课了,然后学习了

POJ 1365 Prime Land

Prime Land Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2972 Accepted: 1362 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,

暑假集训0815

最近打了两场多校和一场中期比赛 中期比赛的话也就那么回事= =水题集合(从各种意义上 两场多校被各种虐,已经弱到谁都可以上(rbq)的程度了TOT 团队配合还要慢慢磨合,毕竟刚刚组队不久 这两次比赛有好几题都是差一点就想出来,毕竟还是图样 继续加油(shui)吧 还有就是一定要好好读题啊!最好读完题之后就手算一下数据,以防理解错题意.如果理解错了不会做就罢了,像中期比赛的时候读完题愉悦的打完代码才发现理解错题意了简直不能忍(论坑队友的正确姿势) Multi-University Training

暑假集训7.11 字符串回文暴力

#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; #define MM(a,b) memset(a,b,sizeof(a)); const double eps = 1e-10; const int i