POJ1365 - Prime Land(质因数分解)
题目大意
给定一个数的质因子表达式,要求你计算机它的值,并减一,再对这个值进行质因数分解,输出表达式
题解
预处理一下,线性筛法筛下素数,然后求出值来之后再用筛选出的素数去分解。。。。其实主要就是字符串处理。。。
代码:
#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(质因数分解)的更多相关文章
- [暑假集训--数论]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 ...
- POJ1365 Prime Land【质因数分解】【素数】【水题】
题目链接: http://poj.org/problem?id=1365 题目大意: 告诉你一个数的质因数x的全部底数pi和幂ei.输出x-1的质因数的全部底数和幂 解题思路: 这道题不难.可是题意特 ...
- POJ1365:质因数分解
Prime Land Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3590 Accepted: 1623 Descri ...
- 2012_p1 质因数分解 (prime.cpp/c/pas)
2012_p1 质因数分解 (prime.cpp/c/pas) 时间限制: 1 Sec 内存限制: 128 MB提交: 80 解决: 27[提交][状态][讨论版][命题人:外部导入] 题目描述 ...
- 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 ...
- LightOJ 1356 Prime Independence(质因数分解+最大独立集+Hopcroft-Carp)
http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1356 题意: 给出n个数,问最多能选几个数,使得该集合中的 ...
- POJ 1365 Prime Land(数论)
题目链接: 传送门 Prime Land Time Limit: 1000MS Memory Limit: 10000K Description Everybody in the Prime ...
- 【BZOJ-4514】数字配对 最大费用最大流 + 质因数分解 + 二分图 + 贪心 + 线性筛
4514: [Sdoi2016]数字配对 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 726 Solved: 309[Submit][Status ...
随机推荐
- Windows下使用cmd启动Oracle EM和sql命令使用+主机身份认证
(1)cmd命令下使用sql命令 >sqlplus / as sysdba sql>select * from v$version; (2)cmd命令下启动Oracle EM 安装完ora ...
- CATextLayer
CATextLayer *layer = [[CATextLayer alloc] init]; layer.frame = CGRectMake(0, 300, 100, 100); 字体模糊 l ...
- C# dynamic
[TestMethod] public void DynamicTest() { dynamic Customer = new ExpandoObject(); Customer.Name = &qu ...
- mysql procedure返回多数据集
返回多数据集写法:第一种 DROP PROCEDURE IF EXISTS `p_query_user` ; DELIMITER // CREATE PROCEDURE p_query_user( p ...
- simplest_dll 最简dll的创建与隐式调用(显式调用太麻烦,个人不建议使用)
首先需要有个头文件,名字随便写 假设test.h //test.h #ifndef _TEST_H #define _TEST_H #ifdef TEST_EXPORTS //通过宏定义控制是输入还 ...
- sjtu1586 Dog
Description 隔壁村的阿黑的Dog没有跑, 但Dog已经15岁了, 相当于人类达到了79岁. 为了防止Dog患上犬类认知障碍 (Canine cognitive dysfunction, C ...
- Unity3D研究院之在把代码混淆过的游戏返混淆回来
最近一直在找如何在MAC上混淆Android的DLL,至今没能找到合适的,有大神知道记得告诉我喔.今天群里有人说了一个混淆代码和返混淆代码的工具de4dot ,不查不知道一查吓一跳.这玩意可以把别人混 ...
- PIXLCLOUND
http://pixlcloud.com/main/career/ https://www.recordedfuture.com/siem-threat-intelligence-part-1/
- SEO 网站页面SEO优化之页面title标题优化
在seo优化中,标题的优化占着举足轻重的地位,无论是从用户体验的角度出发,还是从搜索引擎的排名效果出发,title标题都是页面优化最最重要的因素.笔者总结了优化title标题应该注意的六个方面: ①. ...
- Motion on Ubuntu
Motion is a program that monitors the video signal from one or more cameras and is able to detect if ...