[暑假集训--数论]poj1365 Prime Land
(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
Output
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这么小直接暴力
我也不是很懂这题意义何在,可能是考察输入吧
#include<cstdio>
#include<iostream>
#include<cstring>
#define LL long long
#define int long long
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
} bool mk[];
int pp[],len;
int p[],q[],len2;
int n,s,t;
inline void getp()
{
for (int i=;i<=;i++)
{
if (!mk[i])
{
pp[++len]=i;
for (int j=*i;j<=;j+=i)mk[j]=;
}
}
}
inline int quickpow(int a,int b)
{
int ans=;
while (b)
{
if (b&)ans=ans*a;
a=a*a;
b>>=;
}
return ans;
}
main()
{
getp();
while (~scanf("%lld",&s))
{
if (s==)break;
scanf(" %lld",&t);
n=quickpow(s,t);
char c=getchar();
while (c!='\n'&&c!=EOF)
{
scanf("%lld %lld",&s,&t);
n*=quickpow(s,t);
c=getchar();
}
n--;len2=;
for (int i=;i<=len;i++)
{
if ((LL)pp[i]*pp[i]>n)break;
if (n%pp[i]==)
{
p[++len2]=pp[i];q[len2]=;
while (n%pp[i]==)n/=pp[i],q[len2]++;
}
}
if (n!=||!len2)p[++len2]=n,q[len2]=;
for (int i=len2;i>=;i--)
{
printf("%lld %lld",p[i],q[i]);
if (i==)puts("");else printf(" ");
}
if (c==EOF)break;
}
}
poj 1365
[暑假集训--数论]poj1365 Prime Land的更多相关文章
- 数学--数论--POJ1365——Prime Land
Description Everybody in the Prime Land is using a prime base number system. In this system, each po ...
- [暑假集训--数论]poj1595 Prime Cuts
A prime number is a counting number (1, 2, 3, ...) that is evenly divisible only by 1 and itself. In ...
- [暑假集训--数论]poj3518 Prime Gap
The sequence of n − 1 consecutive composite numbers (positive integers that are not prime and not eq ...
- [暑假集训--数论]hdu2136 Largest prime factor
Everybody knows any number can be combined by the prime number. Now, your task is telling me what po ...
- POJ1365 - Prime Land(质因数分解)
题目大意 给定一个数的质因子表达式,要求你计算机它的值,并减一,再对这个值进行质因数分解,输出表达式 题解 预处理一下,线性筛法筛下素数,然后求出值来之后再用筛选出的素数去分解....其实主要就是字符 ...
- POJ1365 Prime Land【质因数分解】【素数】【水题】
题目链接: http://poj.org/problem?id=1365 题目大意: 告诉你一个数的质因数x的全部底数pi和幂ei.输出x-1的质因数的全部底数和幂 解题思路: 这道题不难.可是题意特 ...
- [暑假集训--数论]poj2262 Goldbach's Conjecture
In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in whic ...
- [暑假集训--数论]poj2909 Goldbach's Conjecture
For any even number n greater than or equal to 4, there exists at least one pair of prime numbers p1 ...
- [暑假集训--数论]poj2773 Happy 2006
Two positive integers are said to be relatively prime to each other if the Great Common Divisor (GCD ...
随机推荐
- java实现微信扫一扫详解
java实现微信扫一扫详解 一.微信JS-SDK参数配置及查找 JS安全域名配置(查找:微信公众号里-公众号设置-功能设置页) 注:1.安全域名外网必须可以访问的到 2.域名不能有下划线 3.要将 ...
- Sum All Odd Fibonacci Numbers-freecodecamp算法题目
Sum All Odd Fibonacci Numbers 1.要求 给一个正整数num,返回小于或等于num的斐波纳契奇数之和. 斐波纳契数列中的前几个数字是 1.1.2.3.5 和 8,随后的每一 ...
- win 系统下制作U盘安装 linux系统
win 系统制作U盘安装硬盘镜像用ultraiso_v9.5.3.2901将Centos.iso写进U盘.安装过程全程区分大小写.过低的ultraiso不能正确读取文件.本文所有资料均能在网上免费下载 ...
- 小程序wafer2操作数据库
小程序操作数据库 //小程序控制台phpmyadmin里给数据库cAuth添加表 //controllers/hello.js const { mysql } = require('../qcloud ...
- nuxt.js服务端缓存lru-cache
对于部分网页进行服务端的缓存,可以获得更好的渲染性能,但是缓存又涉及到一个数据的及时性的问题,所以在及时性和性能之间要有平衡和取舍. 官方文档里面写的使用方法 按照这个配置,试过了没什么用,但是从文档 ...
- Terrorist’s destroy HDU - 4679
Terrorist’s destroy HDU - 4679 There is a city which is built like a tree.A terrorist wants to destr ...
- 统计C语言关键字出现次数
统计C语言关键字出现次数 <C程序设计语言>K&R版本第6章结构6.3结构数组内容 /* Name: 统计c语言关键字出现次数 Copyright: Author: lingr7 ...
- 6 json和ajax传递api数据
1 2 3 4 https://swapi.co/ <h1>Hello Reqwest!</h1> <script> var a = {} reqwest({ ur ...
- Redis实现之数据库(一)
服务器中的数据库 Redis服务器将所有数据库都保存在服务器状态redis.h/redisServer结构体的db数组中,db数组的每个项都是一个redis.h/redisDb结构体,每个redisD ...
- 线段树[To be continued]
目录 数据结构--线段树 一.定义 二.性质 三.基本操作 0.结构体 1.建树 2.单点查询 3.单点修改 4.区间修改 5.区间查询 四.题目 单点修改.区域查询模板 五.鸣谢 学姐的Blog 百 ...