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∞\{pi\}_{i=0}^{∞}{pi}i=0∞​ 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 ekx, ekx−1, . . . , e1, e0,(ekx > 0), that x=pkxekx⋅pkx−1ekx−1⋅⋅⋅⋅⋅p1e1⋅p0e0x = p_{k_x}^{e_{k_x}}· p_{k_{x-1}}^{e_{k_{x−1}}}· · · · · p_1^{e_1}· p_0^{e_0}x=pkx​ekx​​​⋅pkx−1​ekx−1​​​⋅⋅⋅⋅⋅p1e1​​⋅p0e0​​. The sequence
(ekx,ekx−1,...,e1,e0)(e_{k_{x}}, e_{k_{x−1}}, . . . , e_1, e_0)(ekx​​,ekx−1​​,...,e1​,e0​)
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 file 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 file contains one line for each but the last line of the input file. If x is a positive integer contained in a line of the input file, the line in the output file 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 file corresponding to the last “null” line of the input file.
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

问题链接:UVA516 POJ1365 LA5533 ZOJ1261 Prime Land
问题简述:(略)
问题分析:数论筛法问题,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA516 POJ1365 LA5533 ZOJ1261 Prime Land */#include <iostream>
#include <sstream>
#include <vector>
#include <cstring>using namespace std;// 欧拉筛法
const int N = 32767;
bool isprime[N + 1];
int prime[N / 3], pcnt = 0;
void eulersieve(void)
{memset(isprime, true, sizeof(isprime));isprime[0] = isprime[1] = false;for(int i = 2; i <= N; i++) {if(isprime[i])prime[pcnt++] = i;for(int j = 0; j < pcnt && i * prime[j] <= N; j++) {  //筛选isprime[i * prime[j]] = false;if(i % prime[j] == 0) break;}}
}int main()
{std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);eulersieve();string s;while (getline(cin, s) && s[0] != '0') {long long t = 1;int base, pow;istringstream ss(s);while (ss >> base >> pow)while (pow--) t *= base;t -= 1;vector<int> ans;for (int i = pcnt - 1; i >= 0; i--) {if (t % prime[i] == 0) {int cnt = 1;ans.push_back(prime[i]);t /= prime[i];while (t % prime[i] == 0) {cnt++;t /= prime[i];}ans.push_back(cnt);}}for (int i = 0; i < (int)ans.size(); i++)if ( i == (int)ans.size() - 1)cout << ans[i] << endl;elsecout << ans[i] << " ";}return 0;
}

UVA516 POJ1365 LA5533 ZOJ1261 Prime Land【欧拉筛法】相关推荐

  1. 2404 Super Prime(欧拉筛素数)

    2404 Super Prime(欧拉筛素数) Problem Description We all know, prime is a kind of special number which has ...

  2. 质数c语言欧拉筛选,Python|欧拉筛法求质数

    欢迎点击「算法与编程之美」↑关注我们! 本文首发于微信公众号:"算法与编程之美",欢迎关注,及时了解更多此系列文章. 问题描述 我们知道第一个质数是 2.第二个质数是 3.第三个质 ...

  3. 素数计算之埃氏筛法、欧拉筛法

    埃氏筛法 int main() {const int maxNumber=200;int isPrime[maxNumber];int i;int x;for (i=0;i<maxNumber; ...

  4. UVA12043 Divisors【欧拉筛法】

    Let us define the functions d(n) and σ(n) as d(n)=numberofdivisorsofnd(n) = number of divisors of nd ...

  5. UVA10738 Riemann vs Mertens【欧拉筛法】

    One of the biggest, most mathematicians would call it THE biggest, unsolved problems in mathematics ...

  6. UVA12039 Goldbach‘s Cardinality【欧拉筛法】

    Goldbach's cardinality (GC) of an even number means the number of ways the even number can be expres ...

  7. UVA11876 N + NOD (N)【欧拉筛法+前缀和】

    Consider an integer sequence N where, N0 = 1 Ni = Ni−1 + NOD(Ni−1) for i > 0     Here, NOD(x) = n ...

  8. 欧拉筛法(线性筛)的学习理解

    前言 在刚接触编程语言时,对于寻找素数,第一时间想到的便是二重循环暴力查找,其复杂度O(n^2),通过循环中只判断到根号n可以优化一些,不过复杂度也达不到预期.在数论的学习中,我学到了埃氏筛法,O(n ...

  9. 筛质数—(朴素筛法、埃氏筛法、欧拉筛法(线性筛法))

    筛质数时首先要了解质数的定理:1~n中有  个质数 下面再来看具体算法: 1.朴素筛法: 直接把2~n-1中质数和合数的倍数都筛一遍,其代码如下所示: int primes[N],cnt=0; boo ...

最新文章

  1. GitHub日收7000星,Windows计算器项目开源即爆红!
  2. 13.3Runtime 类中的主要方法
  3. The Linux Command Line读书笔记(二)
  4. Java模板引擎之freemarker简介
  5. 通过例子学习 Keystone - 每天5分钟玩转 OpenStack(19)
  6. 2019春季学期第四周作业
  7. 电话骗术升级了,提高警惕! (转自公司内部新闻组,真人真事)
  8. tabel表格制作及操作
  9. 平凡函数依赖是什么?
  10. 11.05T3 map
  11. learning的反义词英文_英语反义词大全.
  12. 秋招一个半月流水账+招银网路科技offer
  13. 【致远FAQ】致远OA宕机之内存溢出
  14. 01-初探MQ-MQ的三大使用场景:应用解耦、异步提速、削峰填谷
  15. windows、mac桌面录制GIF
  16. C++ MFC打开图片并进行简单算法处理
  17. [渝粤教育] 西南科技大学 建筑工程定额与预算 在线考试复习资料2021版(2)
  18. MFC 对话框打印和打印预览知识总结
  19. 基于AI的4G/5G基站节能的智能解决方案
  20. Excel自定义批量替换效率狂甩Ctrl+H!!!

热门文章

  1. 2019-12-02 调用C++高精度时钟 std::chrono::high_resolution_clock的方法
  2. Nginx——安装与虚拟主机配置(域名非80端口问题)
  3. HLSL内置函数一览
  4. pppoe 服务器 无线,centos搭建pppoe拨号服务器
  5. 可以打开md_大祥MD型耐磨卧式多级离心泵现货出售中大泵业
  6. nodejs json转对象_nodejs读取xlsx格式文件
  7. mysql 临时表 主键_MySQL临时表
  8. php_connect_nonb,net2ftp无法显示文件列表输出为空
  9. strategy dynamic参数的使用
  10. 配置两个Hadoop集群Kerberos认证跨域互信(两个集群互通)