CDOJ--1237
原体连接:http://acm.uestc.edu.cn/problem.php?pid=1237
分析:质因子单增;在寻找下一个质因子时,从前一个开始。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int isprime(int s,int n)
{
int i;
for(i=s;i<=sqrt(n);i=i+)
{
if(n%i==)return i;
}
return ;
}
int main()
{
int t,n,m,ans[];
scanf("%d",&t);
while(t--)
{
int cnt=,p;
memset(ans,,sizeof(ans));
scanf("%d",&n);
m=n;
while(n%==)
{
ans[cnt++]=;
n/=;
}
if(n>)
for(int i=;;)
{
if(n==)break;
if(n%i==)
{
ans[cnt++]=i;
n/=i;
}
else
{
p=isprime(i,n);
if(p==)
{
ans[cnt++]=n;
break;
}
else i=p;
}
}
printf("%d=%d",m,ans[]);
for(int i=;i<=cnt-;i++)
printf("*%d",ans[i]);
printf("\n");
}
return ;
}
CDOJ--1237的更多相关文章
- HDU 1237
http://acm.hdu.edu.cn/showproblem.php?pid=1237 表达式计算,方法是中缀转后缀,再计算.中间处理用栈操作 讲解看http://blog.csdn.net/a ...
- cdoj 1489 老司机采花
地址:http://acm.uestc.edu.cn/#/problem/show/1489 题目: 老司机采花 Time Limit: 3000/1000MS (Java/Others) M ...
- gdufs 1237 最优分解问题
题目链接:http://cstfs.gdufs.edu.cn:8080/JudgeOnline/problem.jsp?id=1237 (好像是内网的0.0) 简单来说,这道题目就是把一个数分解为若干 ...
- hdu 1237 简单计算器
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1237 简单计算器 Description 读入一个只包含 +, -, *, / 的非负整数计算表达式, ...
- hihocoder 1237 Farthest Point
#1237 : Farthest Point 时间限制:5000ms 单点时限:1000ms 内存限制:256MB 描述 Given a circle on a two-dimentional pla ...
- BZOJ 1237 配对
Description 你有\(n\)个整数\(A_{i}\)和\(n\)个整数\(B_{i}\).你需要把它们配对,即每个\(A_{i}\)恰好对应一 个\(Bp_{i}\).要求所有配对的整数差的 ...
- 51nod 1237 最大公约数之和 V3(杜教筛)
[题目链接] https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1237 [题目大意] 求[1,n][1,n]最大公约数之和 ...
- caioj 1237: 【最近公共祖先】树上任意两点的距离 在线倍增ST
caioj 1237: [最近公共祖先]树上任意两点的距离 倍增ST 题目链接:http://caioj.cn/problem.php?id=1237 思路: 针对询问次数多的时候,采取倍增求取LCA ...
- 51NOD 1237 最大公约数之和 V3 [杜教筛]
1237 最大公约数之和 V3 题意:求\(\sum_{i=1}^n\sum_{j=1}^n(i,j)\) 令\(A(n)=\sum_{i=1}^n(n,i) = \sum_{d\mid n}d \c ...
- (注意输入格式)bistuoj(旧)1237 成绩统计
成绩统计 Time Limit(Common/Java):1000MS/3000MS Memory Limit:65536KByteTotal Submit:88 ...
随机推荐
- Saving James Bond - Easy Version (MOOC)
06-图2 Saving James Bond - Easy Version (25 分) This time let us consider the situation in the movie & ...
- openstack-r版(rocky)搭建基于centos7.4 的openstack swift对象存储服务 四
openstack-r版(rocky)搭建基于centos7.4 的openstack swift对象存储服务 一 openstack-r版(rocky)搭建基于centos7.4 的openstac ...
- 【Linux 运维】 date的使用
date的使用 一.常用时间格式 #年.月.日 四位年大写,其余小写 [root@localhost ~]# date +%Y #长格式显示四位数年 [root@localhost ~]# date ...
- 华为笔试——C++特定位数比较
题目:特定位数比较 题目介绍:输入两行数据,第一行为 m 个正整数,以空格隔开:第二行为正整数 n ,且 n<= m:要求对第一行的数字的后三位大小进行排序,输出排行 n 的数字,其中,若不满三 ...
- python分割文件目录/文件名和后缀
import os file_path = "D:/test/test.py" (filepath,tempfilename) = os.path.split(file_path) ...
- mysql常用语句入门整理
这篇属于小白入门级别,如果你已经高手可以直接跳过 1.运行数据库mysqld.exe,客户端直接mysql -uroot(root是默认用户名) -p 2 showdatabases,showtabl ...
- Walking Between Houses(贪心+思维)
Walking Between Houses There are nn houses in a row. They are numbered from 11 to nn in order from l ...
- linux awk,sort,uniq,wc,cut命令详解
1.awk awk是行处理器: 相比较屏幕处理的优点,在处理庞大文件时不会出现内存溢出或是处理缓慢的问题,通常用来格式化文本信息 $ 表示当前行 $ 表示第一列 NF 表示一共有多少列 $NF 表示最 ...
- mysql不能启动报error2013错误的解决办法
Mysql mysql lost connection to server during query 问题解决方法 2013-10-16 11:10:53 缘由: 在查询Mysql中的数据库,或者修改 ...
- SQL Server数据库复制
事务复制 事务复制是一种复制类型,对订阅服务器上应用的初始数据快照,然后当发布服务器上发生数据修改时,将捕获到个别的事务并传播到订阅服务. 事务复制的原理是先将发布服务器数据库中的初始快照发送到各订阅 ...