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(分治法+质因数分解)的更多相关文章

  1. POJ 1142 Smith Numbers(史密斯数)

    Description 题目描述 While skimming his phone directory in 1982, Albert Wilansky, a mathematician of Leh ...

  2. poj 1142 Smith Numbers

    Description While skimming his phone directory in 1982, Albert Wilansky, a mathematician of Lehigh U ...

  3. POJ 1845 Sumdiv#质因数分解+二分

    题目链接:http://poj.org/problem?id=1845 关于质因数分解,模板见:http://www.cnblogs.com/atmacmer/p/5285810.html 二分法思想 ...

  4. POJ 1142:Smith Numbers(分解质因数)

                                   Smith Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Submiss ...

  5. Smith Numbers POJ - 1142 (暴力+分治)

    题意:给定一个N,求一个大于N的最小的Smith Numbers,Smith Numbers是一个合数,且分解质因数之后上质因子每一位上的数字之和 等于 其本身每一位数字之和(别的博客偷的题意) 思路 ...

  6. Smith Numbers(分解质因数)

    Smith Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14173   Accepted: 4838 De ...

  7. POJ 2429 long long 质因数分解

    GCD & LCM Inverse Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 16206   Accepted: ...

  8. poj 3714 Raid【(暴力+剪枝) || (分治法+剪枝)】

    题目:  http://poj.org/problem?id=3714 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27048#prob ...

  9. Poj 1401 Factorial(计算N!尾数0的个数——质因数分解)

    一.Description The most important part of a GSM network is so called Base Transceiver Station (BTS). ...

随机推荐

  1. Nginx的安装和配置文件

    一.什么是Nginx 反向代理的高手,可以做web服务器.smtp服务器.ftp服务器,也可以做waf等等.原理,反向代理,收集client请求然后转发给自己lan内的服务器,将请求到的资源回转给客户 ...

  2. 超级小的web手势库AlloyFinger

    针对多点触控设备编程的Web手势组件,快速帮助你的web程序增加手势支持,也不用再担心click 300ms的延迟了.拥有两个版本,无依赖的独立版和react版本.除了Dom对象,也可监听Canvas ...

  3. Express框架(http服务器 + 路由)

    index.js 使用express框架搭建http服务器,和实现路由功能. var express = require('express'); var app = express(); // 主页输 ...

  4. AngularJS』一点小小的理解

    『AngularJS』一点小小的理解   AngularJS 是一个前端的以Javascript为主的MVC框架.与AngularJS相类似的还有EmberJS. 随着时代在进步,各种各样的开发理念与 ...

  5. C#生成唯一码方法

    一.时间戳方法 private string CreateId() { TimeSpan ts = DateTime.UtcNow - , , , , , , ); return Convert.To ...

  6. EDT改成CST

    功能说明:显示文字.语 法:echo [-ne][字符串]或 echo [--help][--version]补充说明:echo会将输入的字符串送往标准输出.输出的字符串间以空白字符隔开, 并在最后加 ...

  7. nginx配置文件内容详情及基本属性配置

    Nginx的配置文件nginx.conf配置详解如下: user nginx nginx ; Nginx用户及组:用户 组.window下不指定 worker_processes 8; 工作进程:数目 ...

  8. php 常用的系统函数

    字符串函数 strlen:获取字符串长度,字节长度 substr_count 某字符串出现的次数 substr:字符串截取,获取字符串(按照字节进行截取) mb_strlenmb_substr str ...

  9. CentOS7使用yum安装LNMP环境以后无法打开php页面

    CentOS7使用yum安装LNMP环境以后无法打开php页面 页面提示为File not found 查看nginx错误日志/var/log/nginx/error.log提示如下 原因分析 ngi ...

  10. Nginx + Tomcat 负载均衡配置详解

    Nginx常用操作指南一.Nginx 与 Tomcat 安装.配置及优化1. 检查和安装依赖项 yum -y install gcc pcre pcre-devel zlib zlib-devel o ...