题目链接:

题目大意:
告诉你一个数的质因数x的全部底数pi和幂ei。输出x-1的质因数的全部底数和幂

解题思路:
这道题不难。可是题意特别不好理解。对于我这样的英文渣的人。愣是一个小时没看明确

关于题意举例说明吧

比如 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【质因数分解】【素数】【水题】的更多相关文章

  1. POJ1365 - Prime Land(质因数分解)

    题目大意 给定一个数的质因子表达式,要求你计算机它的值,并减一,再对这个值进行质因数分解,输出表达式 题解 预处理一下,线性筛法筛下素数,然后求出值来之后再用筛选出的素数去分解....其实主要就是字符 ...

  2. [暑假集训--数论]poj1365 Prime Land

    Everybody in the Prime Land is using a prime base number system. In this system, each positive integ ...

  3. 数学--数论--POJ1365——Prime Land

    Description Everybody in the Prime Land is using a prime base number system. In this system, each po ...

  4. HDU1695:GCD(容斥原理+欧拉函数+质因数分解)好题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1695 题目解析: Given 5 integers: a, b, c, d, k, you're to ...

  5. zzulioj--1775-- 和尚特烦恼1——是不是素数(素数水题)

    1775: 和尚特烦恼1--是不是素数 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 563  Solved: 193 SubmitStatusWeb ...

  6. hdu 4715 Difference Between Primes 2013年ICPC热身赛A题 素数水题

    题意:给出一个偶数(不论正负),求出两个素数a,b,能够满足 a-b=x,素数在1e6以内. 只要用筛选法打出素数表,枚举查询下就行了. 我用set储存素数,然后遍历set里面的元素,查询+x后是否还 ...

  7. 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 ...

  8. 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 ...

  9. POJ1365:质因数分解

    Prime Land Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3590   Accepted: 1623 Descri ...

随机推荐

  1. [Python爬虫] 之二十五:Selenium +phantomjs 利用 pyquery抓取今日头条网数据

    一.介绍 本例子用Selenium +phantomjs爬取今日头条(http://www.toutiao.com/search/?keyword=电视)的资讯信息,输入给定关键字抓取资讯信息. 给定 ...

  2. [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 ...

  3. css - inline\inline-block\block

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. Oracle转化成为百分比

    两种方式都行: ),)||'%' 百分比 from dual; ),'99D99')||'%' 百分比 from dual 第一种方式通过round可以自己选择精确到位数.

  5. 窥探try ... catch与__try ... __except的区别

    VC中的这两个东西肯定谁都用过, 不过它们之间有什么区别, 正好有时间研究了一下, 如果有错误欢迎拍砖.基于VC2005, 32位XP 平台测试通过. 估计对于其他版本的VC和操作系统是不通用的. 1 ...

  6. VS2017 - Winform 简单托盘小程序

    界面比较简单,主要两个button 一个NotifyIcon 和 右键菜单 控件, NotifyIcon 属性,如下: 并为NotifyIcon指定了DoubleClick事件: 主窗体增加两个事件: ...

  7. C#检测浏览器类型 Detect Browser

    private void Button1_Click(object sender, System.EventArgs e) { System.Web.HttpBrowserCapabilities b ...

  8. Angularjs学习笔记7_directive1

    1.基础知识 directive()接受两个参数 · name:字符串,指令的名字 · factory_function:函数,指令的行为 应用启动时,以name作为该应用的标识注册factory_f ...

  9. Docker经常使用命令

    Usage: docker [OPTIONS] COMMAND [arg...]  -H=[unix:///var/run/docker.sock]: tcp://host:port to bind/ ...

  10. zookeeper 批量启动的脚本

    #!/bin/shecho "start zkServer"for i in  2 3 4dossh mini$i "source /etc/profile;/usr/l ...