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 ...
随机推荐
- Yii2-核心框架代码规范
1.概述 简单说,我们使用PSR-2兼容规范,所以应用于PSR-2的一切对我们的代码也同样适用. 文件必须使用 <?php 或 <?= 标签. 文件未尾应该有一个新行. PHP代码文件必须 ...
- angular directive 深入理解
由于业务的需要,最近angular 的diretive 研究的比较多,有和同事一起共同协作开发scada的项目, 对directive 有了进一步更深的理解. 感觉才开始真正理解了这句话的意思: In ...
- vue2 生命周期
转:https://segmentfault.com/a/1190000008570622 生命周期先上图 什么是生命周期 Vue实例有一个完整的生命周期,也就是从开始创建.初始化数据.编译模板.挂载 ...
- java压缩 GZIP进行简单压缩,ZIP进行多文件保存
java压缩 GZIP进行简单压缩,ZIP进行多文件保存 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGlhbmdydWkxOTg4/font/5a6 ...
- [TypeScript] Export public types from your library
If you're a library author, it's useful to expose your public types as interfaces, to allow your con ...
- JAVA实现https单向认证
//关于http 须要两个jar包 httpclient-4.0.jar httpcore-4.0.1.jar private static final HttpClient httpClient = ...
- js常用工具
1.反编译工具 .NET Reflector 2.js检查工具 ReSharper 8.0.14.856 官方原版+注册机 JScript Editor Extensions JSEn ...
- src和href使用总结
src img 图片 <img src="/img/1.png" alt="1" /> rame iframe 框架集 <iframe src ...
- 【设计模式 7】从公司的目前框架和API Gateway,谈谈对外观模式的理解
我,第一次用到外观模式,应该是3年多以前.那时候是做一个收费系统,在当时的U层和B层之间,加了一层Facade.当时,在一些复杂的业务逻辑处理时,感受到了加入外观层的好处,但对于一些简单的(我指的是, ...
- 通过xsd schema结构来验证xml是否合法
import sys import StringIO import lxml from lxml import etree from StringIO import StringIO # Constr ...