zoukankan      html  css  js  c++  java
  • (数学)POJ

    原题链接:http://poj.org/problem?id=1365


    题意:

    定义:任何一个大于1的自然数N,如果N不为质数,那么N可以唯一分解成有限个质数的乘积N=P1a1P2a2P3a3......Pnan,这里P1<P2<P3......<Pn均为质数,其中指数ai是正整数。这样的分解称为N的标准分解式

    告诉你n分解后的结果,底数pi和ei,要你重新分解n-1


    分析:

    一道裸的唯一分解定理题。

    随便瞎几把一写都能A。


    代码:

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<algorithm>
     4 #include<cmath>
     5 #include<cstring>
     6 #include<set>
     7 #include<vector>
     8 #include<queue>
     9 #include<map>
    10 #include<list>
    11 #include<bitset>
    12 #include<string>
    13 #include<cctype>
    14 #include<cstdlib>
    15 #include<sstream>
    16 
    17 using namespace std;
    18 
    19 typedef long long ll;
    20 typedef unsigned long long ull;
    21 #define inf (0x3f3f3f3f)
    22 #define lnf (0x3f3f3f3f3f3f3f3f)
    23 #define eps (1e-8)
    24 int sgn(double a) {
    25     return a < -eps ? -1 : a < eps ? 0 : 1;
    26 }
    27 
    28 const int maxn=1<<16;
    29 bool vis[maxn];
    30 int prime[maxn];
    31 
    32 int Euler_prime() {
    33     memset(vis, true, sizeof(vis));
    34     int tot = 0;
    35     for (int i = 2; i < maxn; i++) {
    36         if (vis[i]) prime[tot++] = i;
    37         for (int j = 0; j < tot&&prime[j] * i < maxn; j++) {
    38             vis[i*prime[j]] = false;
    39             if (i%prime[j] == 0) break;
    40         }
    41     }
    42     return tot;
    43 }
    44 string line;
    45 
    46 
    47 
    48 void solve() {
    49     int pn=Euler_prime();
    50     while(getline(cin,line)){
    51         if(line=="0")break;
    52         ll sum=1;
    53         int p,e;
    54         stringstream ss(line);
    55         while(ss>>p>>e){
    56             for(int i=0;i<e;i++){
    57                 sum*=p;
    58             }
    59         }
    60         sum--;
    61         for(int i=pn-1;i>=0;i--){
    62             if(sum%prime[i]==0){
    63                 cout<<prime[i]<<" ";
    64                 int e=0;
    65                 while(sum%prime[i]==0){
    66                     sum/=prime[i];
    67                     e++;
    68                 }
    69                 cout<<e<<" ";
    70             }
    71             if(sum==1)break;
    72         }
    73         cout<<endl;
    74 
    75     }
    76 }
    77 
    78 
    79 
    80 int main() {
    81 
    82 #ifndef ONLINE_JUDGE
    83     freopen("in.txt", "r", stdin);
    84     //freopen("out.txt", "w", stdout);
    85 #endif
    86     iostream::sync_with_stdio(false);
    87     solve();
    88     return 0;
    89 }
  • 相关阅读:
    mybatis 绑定 statement 失败
    JDBC链接Mysql失败
    Mysql 链接数据库时区错误
    mybatis 延迟加载
    C++ 虚函数表解析
    运行错误:error while loading shared libraries: xxx.so.0:cannot open shared object file: No such file or
    QComboBox的activated与currentIndexChanged的区别
    QT 文件对话框(QFileDialog)
    VS2010 ERROR:c1xx fatal error c1083
    django 在字符串[str(list)]中精确查找
  • 原文地址:https://www.cnblogs.com/tak-fate/p/5910790.html
Copyright © 2011-2022 走看看