[暑假集训--数论]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
poj 1365
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
相关文章推荐
- [2016/8/2][暑假集训]数论基础
- [暑假集训--数论]poj1061 青蛙的约会
- [暑假集训--数论]poj2773 Happy 2006
- [暑假集训--数论]poj2657 Comfort
- [暑假集训--数论]poj2142 The Balance
- 暑假集训-组合数学及数论
- [暑假集训--数论]poj1730 Perfect Pth Powers
- [暑假集训--数论]poj3518 Prime Gap
- [暑假集训--数论]poj2909 Goldbach's Conjecture
- [暑假集训--数论]poj2262 Goldbach's Conjecture
- [暑假集训--数论]poj1595 Prime Cuts
- [暑假集训--数论]poj2034 Anti-prime Sequences
- [暑假集训--数论]poj2115 C Looooops
- [暑假集训--数论]hdu1019 Least Common Multiple
- [暑假集训--数论]hdu2136 Largest prime factor
- 暑假集训-组合数学及数论
- 2013暑假集训第二天上午总结
- 13暑假集训#10 总结
- 2013ACM暑假集训总结-致将走上大三征途的我
- 暑假集训第1天链表-数据结构实验之链表四:单链表的归并