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

思路:主要是分治:分解成质因子使用递归即可。

#include<cstdio>
#include<cmath>
// 检测素数
bool is_prime(int n)
{
for (int i = ; i*i <= n;++i)
if (n%i == ){ return ; }
return ;
}
//数位
int sumfun(int n)
{
int ans = ;
while (n){ ans += n % ; ; n /= ; }
return ans;
}
//分治
int che(int n)
{
if (is_prime(n))return sumfun(n);
else
{
int m = (int)sqrt(n + 0.5);
for (int i = m; i >; --i)
{
if (n%i == )
return che(i) + che(n / i);
}
}
}
int main()
{
int n;
while (scanf("%d", &n)!=EOF && n)
{
while (n++)
{
if (!is_prime(n)&&sumfun(n) == che(n)){
printf("%d\n", n);
break;
}
}
}
}

Smith Numbers POJ - 1142 (暴力+分治)的更多相关文章

  1. Smith Numbers POJ - 1142 暴力递归枚举

    题意: 给你一个数x,把这个分解成素数之积(假设是x1*x2*x3),如果   x的每一数位的和   等于  x1每一数位的和加上x2每一数位的和加上x3每一数位的和,那么他就是题目要找的数 示例: ...

  2. A - Smith Numbers POJ

    While skimming his phone directory in 1982, Albert Wilansky, a mathematician of Lehigh University,no ...

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

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

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

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

  5. poj 1142 Smith Numbers

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

  6. poj1142 Smith Numbers

    Poj1142 Smith Numbers Smith Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13854 ...

  7. Smith Numbers - PC110706

    欢迎访问我的新博客:http://www.milkcu.com/blog/ 原文地址:http://www.milkcu.com/blog/archives/uva10042.html 原创:Smit ...

  8. POJ 2182/暴力/BIT/线段树

    POJ 2182 暴力 /* 题意: 一个带有权值[1,n]的序列,给出每个数的前面比该数小的数的个数,当然比一个数前面比第一个数小的个数是0,省略不写,求真正的序列.(拗口) 首先想到的是从前到后暴 ...

  9. UVA 10042 Smith Numbers(数论)

    Smith Numbers Background While skimming his phone directory in 1982, Albert Wilansky, a mathematicia ...

随机推荐

  1. Mybatis之分页插件pagehelper的简单使用

    最近从家里回来之后一直在想着减肥的事情,一个月都没更新博客了,今天下午没睡午觉就想着把mybatis的分页插件了解一下,由于上个月重新恢复了系统,之前创建的项目都没了,又重新创建了一个项目. 一.创建 ...

  2. 深入理解JVM——对象

    对象的创建 虚拟机遇到一条new指令时,首先检查指令的参数能否在常量池中定位到一个类的符号引用,并且检查这个符号引用代表的类是否已经被加载.解析和初始化过.如果没有,必须先执行相应的类加载过程. 接下 ...

  3. MVC中的HtmlHelper详解

    熟悉MVC开发的朋友都应该知道在MVC中,每一个Controller都对应一个View,并且CS文件和对应的ASPX文件也被分离了,更重要的是不再有服务器端控件在工具箱中,不再是代码后至了.MVC中的 ...

  4. JavaScript--fullPage.js插件

    GitHub:https://github.com/alvarotrigo/fullPage.js FullPage.js是一个基于JQuery的插件,可以很方便的制作出全屏网站; 一 特点: 1.支 ...

  5. WebGL学习笔记(一)

    作者:朱金灿 来源:http://blog.csdn.net/clever101 (一)WebGL是什么? WebGL是一门在网页上显示三维图形的技术,你可以把它理解为把OpenGL从C/S端搬到了B ...

  6. ionic打包报错Execution failed for task ':processDebugResources'

    ionic 打包的时候报了这样一个错误:Execution failed for task ':processDebugResources' 分析: compile "com.android ...

  7. Android View体系(三)属性动画

    上一篇文章讲了View滑动的六种方法,其中一种是使用动画,这篇文章我们来讲一讲动画的其中一种:属性动画. 1.android视图动画和属性动画 视图动画我们都了解,它提供了AlphaAnimation ...

  8. WANem广域网环境模拟

    背景 在测试过程中,往往需要模拟网络环境较差情况下,体验情况,故引入广域网模拟工具辅助测试 安装WANem 步骤1:光盘引导WANem镜像: 步骤2:启动(或者新建虚拟机——选择other insal ...

  9. 洗礼灵魂,修炼python(52)--爬虫篇—【转载】爬虫工具列表

    与爬虫相关的常用模块列表. 原文出处:传送门链接 网络 通用 urllib -网络库(stdlib). requests -网络库. grab – 网络库(基于pycurl). pycurl – 网络 ...

  10. Python scikit-learn (metrics): difference between r2_score and explained_variance_score?

    I noticed that that 'r2_score' and 'explained_variance_score' are both build-in sklearn.metrics meth ...