Prime Land
http://poj.org/problem?id=1365
题意:给定一个数字n的拆分形式,然后让你求解n-1的值;
解析:直接爆搞
// File Name: poj1365.cpp
// Author: bo_jwolf
// Created Time: 2013骞?0鏈?9鏃?鏄熸湡涓?21:29:25 #include<vector>
#include<list>
#include<map>
#include<set>
#include<deque>
#include<stack>
#include<bitset>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<ctime> using namespace std;
vector<int> prime, ans;
const int maxn = 40000;
int unprime[ maxn ];
int main(){
unprime[ 0 ] = unprime[ 1 ] = true;
for( int i = 2; i < maxn; ++i ){
if( !unprime[ i ] ){
prime.push_back( i );
for( int j = i + i; j < maxn; j += i ){
unprime[ j ] = true;
}
}
}
int n, p;
string line;
while( getline( cin, line ),line[ 0 ] != 48 ){
ans.clear();
istringstream stream( line );
long long sum = 1;
while( stream >> n >> p ){
while( p-- ){
sum *= n;
}
} sum -= 1;
for( int i = prime.size() - 1; i >= 0; --i ){
if( sum % prime[ i ] == 0 ){
ans.push_back( prime[ i ] );
int temp = 0;
while( sum % prime[ i ] == 0 ){
sum /= prime[ i ];
temp++;
}
ans.push_back( temp );
}
}
for( int i = 0 ; i < ans.size(); ++i ){
cout << ans[ i ] << ( i == ans.size() - 1 ?'\n':' ' );
}
}
return 0;
}
Prime Land的更多相关文章
- POJ 1365 Prime Land(数论)
题目链接: 传送门 Prime Land Time Limit: 1000MS Memory Limit: 10000K Description Everybody in the Prime ...
- [POJ 1365] Prime Land
Prime Land Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3211 Accepted: 1473 Descri ...
- [暑假集训--数论]poj1365 Prime Land
Everybody in the Prime Land is using a prime base number system. In this system, each positive integ ...
- 数学--数论--POJ1365——Prime Land
Description Everybody in the Prime Land is using a prime base number system. In this system, each po ...
- POJ1365 - Prime Land(质因数分解)
题目大意 给定一个数的质因子表达式,要求你计算机它的值,并减一,再对这个值进行质因数分解,输出表达式 题解 预处理一下,线性筛法筛下素数,然后求出值来之后再用筛选出的素数去分解....其实主要就是字符 ...
- POJ 1365 Prime Land(整数拆分)
题意:感觉题意不太好懂,题目并不难,就是给一些p和e,p是素数,e是指数,然后把这个数求出来,设为x,然后让我们逆过程输出x-1的素数拆分形式,形式与输入保持一致. 思路:素数打表以后正常拆分即可. ...
- POJ1365 Prime Land【质因数分解】【素数】【水题】
题目链接: http://poj.org/problem?id=1365 题目大意: 告诉你一个数的质因数x的全部底数pi和幂ei.输出x-1的质因数的全部底数和幂 解题思路: 这道题不难.可是题意特 ...
- 筛选法 || POJ 1356 Prime Land
英文题读不懂题==质数幂的形式给你一个数 把它减一再用质数幂的形式表示出来 *解法:质数从小到大模拟除一遍,输入有点别扭 #include <iostream> #include < ...
- pku1365 Prime Land (数论,合数分解模板)
题意:给你一个个数对a, b 表示ab这样的每个数相乘的一个数n,求n-1的质数因子并且每个指数因子k所对应的次数 h. 先把合数分解模板乖乖放上: ; ans != ; ++i) { ) { num ...
随机推荐
- Get your Windows product key from a script
The product key is located in the registry under HKLM\Software\Microsoft\Windows NT\CurrentVersion I ...
- Static File Middleware
[ASP.NET Core] Static File Middleware 前言 本篇文章介绍ASP.NET Core里,用来处理静态档案的Middleware,为自己留个纪录也希望能帮助到有需要 ...
- UICountingLabel实现数字变化的动画效果-b
在大多数金融类 app 上或者其他 app 需要数字展示的地方, 经常会有如下的动画效果: 动画效果 怎么做呢? 一.下载UICountingLabel 下载地址: https://github.co ...
- php 获取图片、swf的尺寸大小
PHP获取图片大小函数. getimagesize() 能够得到图片及flash(swf)的大小. 语法 1 list($width, $height, $type, $attr) = getima ...
- 如何解决eclipse中的中文乱码问题:
方法一:代码里面进行改变编码 1. 编码方式的gbk和utf不同,不可以互相转换,只有byte和utf或者byte和gbk之间的转换,之间的转码如下:
- simplemodal — jquery弹出窗体插件
方式一:使用jquery-1.7.1.min.js(1.9.1的版本我试过了,不行) + jquery_modal.js的方式 文件: testModel.css: /* Overlay ...
- Spring事务传播特性的浅析——事务方法嵌套调用的迷茫
Spring事务传播机制回顾 Spring事务一个被讹传很广说法是:一个事务方法不应该调用另一个事务方法,否则将产生两个事务.结果造成开发人员在设计事务方法时束手束脚,生怕一不小心就踩到地雷. 其实这 ...
- lunux下查看文件文件夹大小的命令
使用ls -lht命令显示当前目录下的所有文件,其中有一列就是显示这个文件的大小.如果要看一个文件夹的大小,可以用du -sh *
- 【原创翻译】The Case for the Reduced Instruction Set Computer
RISC机的例子 David A. Patterson 加州大学伯克利分校计算机科学系 David R. Ditzel 贝尔实验室计算科学研究中心 介绍 计算机体系结构最主要的目标之一就是设计比之前产 ...
- HTML颜色编码
Web安全色 #000000 #000033 #000066 #000099 #0000CC #0000FF #003300 #003333 #003366 #003399 #0033CC #0033 ...