题目链接:

题目大意:
告诉你一个数的质因数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. mahout运行测试与数据挖掘算法之聚类分析(一)kmeans算法解析

    在使用mahout之前要安装并启动hadoop集群 将mahout的包上传至linux中并解压即可 mahout下载地址: 点击打开链接 mahout中的算法大致可以分为三大类: 聚类,协同过滤和分类 ...

  2. JavaScript basics: 2 ways to get child elements with JavaScript

    原文: https://blog.mrfrontend.org/2017/10/2-ways-get-child-elements-javascript/ Along the lines of oth ...

  3. Node.js nvshens图片批量下载爬虫 1.00

    //====================================================== // www.nvshens.com图片批量下载Node.js爬虫1.00 // 此程 ...

  4. 倍福TwinCAT(贝福Beckhoff)常见问题(FAQ)-点击运行按钮进入到运行状态报错Error starting TwinCAT System怎么办 AdsWarning1823怎么办

    一般提示如下   点击Device,然后选中当前真正连接到的网卡   一般是由于重装系统之后,没有把本来是realtime capable的设备Install,所以找不到支持EtherCAT的设备导致 ...

  5. ThreadLocal的简单使用(读书笔记)

         从ThreadLocal的名字上可以看到,这是一个线程局部变量,也就是说,只有当前线程可以访问,既然是只有当前线程可以访问的数据,自然是线程安全的. public class ThreadL ...

  6. centos 6.5 下使用nginx 反向代理 多个tornado

    centos 6.5 nginx 1.4.4 /etc/nginx/conf.d 下创建tornado.conf upstream tornado { server 127.0.0.1:8887; s ...

  7. 使用Google-Authenticator加强serverSSH登录

    对于须要特殊加密的人群,我这里给出对应的方法来进行谷歌式加密. 过程例如以下: 准备: 首先在你的手机上准备好client(自己百度下载) 接下来依照命令做: date 查看系统时间       da ...

  8. Unity3D在WebPlayer模式下的异常上报探索

    原地址:http://www.cnblogs.com/hisiqi/archive/2013/07/21/3203527.html 我们知道,Unity3D在WebPlayer的发布模式下是沙箱环境中 ...

  9. Android_View_得到Activity

    Context context = view.getContext(); if (context instanceof Activity){ Activity activity = (Activity ...

  10. unity, 集成iOS广告sdk注意事项

    ----更新:2015-10-22 今天在unity里集成讯飞语音听写的iOS sdk,结果发现前面集成domob广告的方法搞复杂了. 其实,直接把UnityViewControllerBase当做s ...