zoukankan      html  css  js  c++  java
  • [暑假集训--数论]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!='
    '&&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
  • 相关阅读:
    Nginx详解(正向代理、反向代理、负载均衡原理)
    java List的初始化
    nginx配置实现负载均衡
    SQL中where与having的区别
    数据库中where与having区别~~~
    group by的使用
    wm_concat函数
    Nginx配置upstream实现负载均衡1
    Nginx配置upstream实现负载均衡
    java
  • 原文地址:https://www.cnblogs.com/zhber/p/7285484.html
Copyright © 2011-2022 走看看