POJ1365 Prime Land【质因数分解】【素数】【水题】
关于题意举例说明吧
比如 509 1 59 1
x = 509^1 * 59^1 = 30031
x-1 = 30030
则答案 13 1 11 1 7 1 5 1 3 1 2 1 就是 x-1 = 13^1 * 11^1 * 7^1 * 5^1 *3^1 *2^1
= 30031
那么直接按着题意暴力解决即可了。
。。
。。
AC代码:
#include<stdio.h>
#include<string.h>
#include<math.h>
/*
pow函数说明
原型:extern float pow(float x, float y);
使用方法:#include <math.h>
功能:计算x的y次幂。
说明:x应大于零,返回幂指数的结果。
*/
double p[110],e[110];
int Prime[35000],E[35000]; void IsPrime()
{
Prime[0] = Prime[1] = 0;
for(int i = 2; i <= 35000; i++)
{
Prime[i] = 1;
}
for(int i = 2; i <= 35000; i++)
{
for(int j = i+i; j <= 35000; j+=i)
{
Prime[j] = 0;
}
}
}
int main()
{
int count,sign;
IsPrime();
// for(int i = 2; i <= 35000; i++)
// if(Prime[i])
// printf("%d ",i);
while(1)
{
count = 0,sign = 0;
memset(p,0,sizeof(p));
memset(e,0,sizeof(e));
memset(E,0,sizeof(E)); while(1)
{
scanf("%lf",&p[count]);
if(p[count] == 0)
{
sign = 1;
break;
}
scanf("%lf",&e[count]);
count++;
char c = getchar();
if(c=='\n')
break;
} if(sign == 1)
break; double num = 1;
for(int i = 0; i < count; i++)
num *= pow(p[i],e[i]); int sum = (int)num - 1;
// printf("%d\n",sum);
int flag = 0,pos = 2;
for(int i = 2; i <= 32767; i++)
{
if(sum == 1)
break;
if(Prime[i])
{
while(sum % i == 0)
{
E[i]++;
sum /= i;
if(flag == 0)
{
flag = 1;
pos = i;
}
}
}
} for(int i = 32767; i>= 2; i--)
{
if(E[i]!=0 && i!=pos)
printf("%d %d ",i,E[i]);
else if(E[i]!=0 && i==pos)
{
printf("%d %d\n",i,E[i]);
break;
}
}
} return 0;
}
POJ1365 Prime Land【质因数分解】【素数】【水题】的更多相关文章
- POJ1365 - Prime Land(质因数分解)
题目大意 给定一个数的质因子表达式,要求你计算机它的值,并减一,再对这个值进行质因数分解,输出表达式 题解 预处理一下,线性筛法筛下素数,然后求出值来之后再用筛选出的素数去分解....其实主要就是字符 ...
- [暑假集训--数论]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 ...
- HDU1695:GCD(容斥原理+欧拉函数+质因数分解)好题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1695 题目解析: Given 5 integers: a, b, c, d, k, you're to ...
- zzulioj--1775-- 和尚特烦恼1——是不是素数(素数水题)
1775: 和尚特烦恼1--是不是素数 Time Limit: 2 Sec Memory Limit: 128 MB Submit: 563 Solved: 193 SubmitStatusWeb ...
- hdu 4715 Difference Between Primes 2013年ICPC热身赛A题 素数水题
题意:给出一个偶数(不论正负),求出两个素数a,b,能够满足 a-b=x,素数在1e6以内. 只要用筛选法打出素数表,枚举查询下就行了. 我用set储存素数,然后遍历set里面的元素,查询+x后是否还 ...
- codeforces 558A A. Lala Land and Apple Trees(水题)
题目链接: A. Lala Land and Apple Trees time limit per test 1 second memory limit per test 256 megabytes ...
- Codeforces Round #304 (Div. 2) D. Soldier and Number Game 素数打表+质因数分解
D. Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes input s ...
- POJ1365:质因数分解
Prime Land Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3590 Accepted: 1623 Descri ...
随机推荐
- Linux源码编译安装MySQL5.7
目录[-] 一.环境准备: 二.升级系统: 三.做一些准备工作(以下Linux命令均在su到root用户操作): 四.开始编译安装mysql-5.7.9: 一.环境准备: 我尝试过以下环境都是能成功的 ...
- 使用IntelliJ IDEA创建Maven多模块项目
转载:http://blog.csdn.net/xyw591238/article/details/52794788 使用Maven管理项目时,往往需要创建多个模块,模块之间存在相互引用的关系.对于M ...
- python——深刻理解Python中的元类(metaclass)
译注:这是一篇在Stack overflow上 很热的帖子.提问者自称已经掌握了有关Python OOP编程中的各种概念,但始终觉得元类(metaclass)难以理解.他知道这肯定和自省有关,但仍然觉 ...
- python——socket模块与列表映射
从socket模块学习中的一段奇怪代码说起 前言:在学习python标准库中的Socket模块中,发现了一段奇怪的代码. import socket def get_constants(prefix) ...
- Hackerrank - Game Of Rotation 题解
旋转一个数组以得到最大值. 陷阱就是:不能排序.须要模拟操作旋转,并设计公式计算旋转后的和. 要求是O(n)时间完毕. 原题: https://www.hackerrank.com/challenge ...
- c++opencv项目移植到Android(Mat—》IplImage*)
近期将PC机上的行人检測的C++项目移植到Android平台遇到非常多的问题.因此,记录一些重点. 1. 最好能够參照Opencv sample 里面的mix-processing. 2. 数据结构的 ...
- 今日头条&58转转笔试
昨天参加今日头条和58转转的笔试,因为时间上有冲突,所以主要选择参加头条的笔试. 先说头条: 头条的题型: 一道改错题 三道编程题 一道设计题 感受: 做题目的的时候还是有点紧张的,因为突然遇到题目需 ...
- Openlayer4 - 最好最强大的开源地图引擎
Openlayer4 - 最好最强大的开源地图引擎 # githubhttps://github.com/openlayers/openlayers # 官网http://openlayers.org ...
- unity, 自定义类中使用print
在unity脚本中自定义c#类,而且不继承MonoBehaviour的话,若还想在其中使用print函数,可以用MonoBehaviour.print(...).
- Atitit.获取swing ui 按钮控件的id 与名字 与JPDA 调试体系
Atitit.获取swing ui 按钮控件的id 与名字 与JPDA 调试体系 1. Swing Inspector是一个Java Swing/AWT用户界面分析和调试工具,功能与firebug类似 ...