题目大意

给定一个数的质因子表达式,要求你计算机它的值,并减一,再对这个值进行质因数分解,输出表达式

题解

预处理一下,线性筛法筛下素数,然后求出值来之后再用筛选出的素数去分解。。。。其实主要就是字符串处理。。。

代码:

#include <stdio.h>
#include <string.h>
#include <math.h>
#define MAXN 10000
char str[MAXN],s[MAXN][7];
int prime[MAXN*5],cnt=0;
bool check[MAXN*5];
void get_prime()
{
int high=MAXN*5;
memset(check,false,true);
for(int i=2; i<=high; i++)
{
if(!check[i])
prime[cnt++]=i;
for(int j=0; j<cnt&&i*prime[j]<=high; j++)
{
check[i*prime[j]]=true;
if(i%prime[j]==0) break;
}
}
}
int get_sum(char *s)
{
int sum=0,len=strlen(s);
for(int i=0;i<len;i++)
sum=sum*10+s[i]-'0';
return sum;
}
int main()
{
char *p;
int ans;
get_prime();
while(gets(str))
{
bool first=false;
if(str[0]=='0') break;
int len=0;
p=strtok(str," ");
while (p!=NULL)
{
strcpy(s[len++],p);
p=strtok(NULL," ");
}
ans=1;
for(int i=0; i<len; i+=2)
{
int a,b;
a=get_sum(s[i]);
b=get_sum(s[i+1]);
ans*=(int)(pow(a*1.0,b*1.0));
}
ans--;
for(int i=cnt-1;i>=0&&ans!=1;i--)
{
if(ans%prime[i]==0)
{
int p=0;
while(ans%prime[i]==0)
{
p++;
ans/=prime[i];
}
if(!first)
{
printf("%d %d",prime[i],p);
first=true;
}
else
printf(" %d %d",prime[i],p);
}
}
printf("\n");
}
return 0;
}

POJ1365 - Prime Land(质因数分解)的更多相关文章

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

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

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

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

  3. POJ1365 Prime Land【质因数分解】【素数】【水题】

    题目链接: http://poj.org/problem?id=1365 题目大意: 告诉你一个数的质因数x的全部底数pi和幂ei.输出x-1的质因数的全部底数和幂 解题思路: 这道题不难.可是题意特 ...

  4. POJ1365:质因数分解

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

  5. 2012_p1 质因数分解 (prime.cpp/c/pas)

    2012_p1 质因数分解 (prime.cpp/c/pas) 时间限制: 1 Sec  内存限制: 128 MB提交: 80  解决: 27[提交][状态][讨论版][命题人:外部导入] 题目描述 ...

  6. PAT 甲级 1059 Prime Factors (25 分) ((新学)快速质因数分解,注意1=1)

    1059 Prime Factors (25 分)   Given any positive integer N, you are supposed to find all of its prime ...

  7. LightOJ 1356 Prime Independence(质因数分解+最大独立集+Hopcroft-Carp)

    http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1356 题意: 给出n个数,问最多能选几个数,使得该集合中的 ...

  8. POJ 1365 Prime Land(数论)

    题目链接: 传送门 Prime Land Time Limit: 1000MS     Memory Limit: 10000K Description Everybody in the Prime ...

  9. 【BZOJ-4514】数字配对 最大费用最大流 + 质因数分解 + 二分图 + 贪心 + 线性筛

    4514: [Sdoi2016]数字配对 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 726  Solved: 309[Submit][Status ...

随机推荐

  1. sqlserver 2008express版本启用混合登陆和sa

    本机环境:win10 64位  vs2010及其自带的数据库 sqlserver2008 express版本 用命令行登陆数据库: osql -E -Slocalhost\sqlexpress 登陆成 ...

  2. loadrunner_Controller技巧_overlay

    在scenario运行期间,我们经常有类似于:总结Vu数变化,Tps 或者response time变化的趋势或者对比response time 和 tps,那么我们就用的到 Controller的图 ...

  3. 手游:cocos2d-x3.0 移植 wp8 开发 各种 “蛋疼”问题的汇总

    蛋疼的问题的起源: wp8 做应用开发,显示显示中文,源码包含中文都是没有一点问题的, 只是cocos2d-x 的编码方式(UTF-8),引起的一系列的问题. 1:不能显示服务器返回的中文 2:c++ ...

  4. delphi中的各种文件类型介绍

    1.DPR: Delphi Project文件,包含了Pascal代码.应用系统的工程文件2.PAS: Pascal文件,Pascal单元的源代码,可以是与窗体有关的单元或是独立的单元.3.DFM:D ...

  5. 169. Majority Element

    题目: Given an array of size n, find the majority element. The majority element is the element that ap ...

  6. grep简单常用的语法介绍

    说明: grep -n 关键字 查询的文档 ->-n表示打印行号 grep -c 关键字 查询的文档1 查询的文档2 ->-c表示输出匹配行的数目,而不是输出匹配的行. grep -rn ...

  7. S3C2410 实验三——跑马灯实验

    http://www.evernote.com/shard/s307/sh/f2a748e7-34c4-4ce6-acac-82a756cc9e82/ad5813188d655e504857970db ...

  8. S5PV210的IRAM应用

    准备分析   IRAM的大小96k,其实前两个程序都在这里运行的,程序都小于16K.要实现的是从把IRAM从的前16k从IRAM的起始地址0xD0020000拷贝到0xD0024000 处,调用mai ...

  9. FORM Save : ORA-01403 FRM-40735 ORA-06502

    症状: FORM开发后挂上服务器后,运行保存按键提示: ORA-01403: 未找到任何数据 ----------------------------------------------------- ...

  10. hadoop异常: 到目前为止解决的最牛逼的一个异常(java.io.IOException: Incompatible clusterIDs)

    (注意: 本人用的版本为hadoop2.2.0, 旧的版本和此版本的解决方法不同) 异常为: 9 (storage id DS-2102177634-172.16.102.203-50010-1384 ...