您的位置:首页 > 其它

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

2017-08-04 15:37 381 查看
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

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: