POJ 1142 Smith Numbers(分治法+质因数分解)
http://poj.org/problem?id=1142
题意:
给出一个数n,求大于n的最小数,它满足各位数相加等于该数分解质因数的各位相加。
思路:
直接暴力。
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
using namespace std; int n; int cacl(int x)
{
int sum = ;
while (x)
{
sum += x % ;
x /= ;
}
return sum;
} bool isprime(int x)
{
int m = sqrt(x + 0.5);
for (int i = ; i <= m; i++)
{
if (x%i == ) return false;
}
return true;
} int solve(int x)
{
if (isprime(x))
return cacl(x);
else
{
int m = sqrt(x + 0.5);
for (int i = m; i >;i--)
if (x%i == )
return solve(i) + solve(x / i);
}
} int main()
{
//freopen("D:\\input.txt", "r", stdin);
while (~scanf("%d", &n) && n)
{
for (int i = n + ;; i++)
{
if (!isprime(i) && cacl(i) == solve(i))
{
printf("%d\n", i);
break;
}
}
}
return ;
}
POJ 1142 Smith Numbers(分治法+质因数分解)的更多相关文章
- POJ 1142 Smith Numbers(史密斯数)
Description 题目描述 While skimming his phone directory in 1982, Albert Wilansky, a mathematician of Leh ...
- poj 1142 Smith Numbers
Description While skimming his phone directory in 1982, Albert Wilansky, a mathematician of Lehigh U ...
- POJ 1845 Sumdiv#质因数分解+二分
题目链接:http://poj.org/problem?id=1845 关于质因数分解,模板见:http://www.cnblogs.com/atmacmer/p/5285810.html 二分法思想 ...
- POJ 1142:Smith Numbers(分解质因数)
Smith Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submiss ...
- Smith Numbers POJ - 1142 (暴力+分治)
题意:给定一个N,求一个大于N的最小的Smith Numbers,Smith Numbers是一个合数,且分解质因数之后上质因子每一位上的数字之和 等于 其本身每一位数字之和(别的博客偷的题意) 思路 ...
- Smith Numbers(分解质因数)
Smith Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14173 Accepted: 4838 De ...
- POJ 2429 long long 质因数分解
GCD & LCM Inverse Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 16206 Accepted: ...
- poj 3714 Raid【(暴力+剪枝) || (分治法+剪枝)】
题目: http://poj.org/problem?id=3714 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27048#prob ...
- Poj 1401 Factorial(计算N!尾数0的个数——质因数分解)
一.Description The most important part of a GSM network is so called Base Transceiver Station (BTS). ...
随机推荐
- Array数组去重
1.循环方法 function methodOne(arr){ var result = [], arrLen = arr.length, item = null, i,j; for(var i = ...
- [Fine Uploader] 用Fine Uploader+ASP.NET MVC实现ajax文件上传[代码示例]
Fine Uploader(http://fineuploader.com/)是一个实现 ajax 上传文件的 Javascript 组件 This project attempts to ach ...
- shell出现syntax error near unexpected token `<' 解决方法
最新在看一个shell资料时,按照教材,却出现如下错误,不能运行 如下,简单的脚本: #!/bin/bash cat |while read line do echo $line done < ...
- redis运维常用的server端命令
TIME 查看时间戳与微秒数 DBSIZE 查看当前库中的key数量 BGREWRITEAOF 后台进程重写AOF BGSAVE 后台保存rdb快照 SAVE 保存rdb快照 LASTSAVE 上次保 ...
- INSERT高级应用
INSERT INTO departments VALUES (departments_seq.nextval, 'Entertainment', 162, 1400); INSERT INTO em ...
- asp.net 下载文件几种方式
protected void Button1_Click(object sender, EventArgs e) { /* 微软为Response对象提供了一个新的方法TransmitFile来解决使 ...
- CentOS7使用yum安装LNMP环境以后无法打开php页面
CentOS7使用yum安装LNMP环境以后无法打开php页面 页面提示为File not found 查看nginx错误日志/var/log/nginx/error.log提示如下 原因分析 ngi ...
- Oracle HA 之 基于活动数据库复制配置oracle 11.2 dataguard
规划:主库:db_name=dbking db_unique_name=dbkingpri 备库:db_name=dbking ...
- mysql_commit() COMMIT ROLLBACK 提交 回滚 连接释放
MySQL :: MySQL 8.0 Reference Manual :: 28.7.7.6 mysql_commit() https://dev.mysql.com/doc/refman/8.0/ ...
- IT运营新世界大会:广通软件开启双态运维大时代
10月28日,第一届“IT运营新世界大会”在北京成功举办.大会上由10家ITOM领域的标杆企业宣布结成“ITOM联盟”. 广通软件(证券代码:833322)作为大会的创始成员全程推动见证了这一历史时刻 ...