Smith Numbers POJ - 1142 (暴力+分治)
题意:给定一个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 (暴力+分治)的更多相关文章
- Smith Numbers POJ - 1142 暴力递归枚举
题意: 给你一个数x,把这个分解成素数之积(假设是x1*x2*x3),如果 x的每一数位的和 等于 x1每一数位的和加上x2每一数位的和加上x3每一数位的和,那么他就是题目要找的数 示例: ...
- A - Smith Numbers POJ
While skimming his phone directory in 1982, Albert Wilansky, a mathematician of Lehigh University,no ...
- POJ 1142 Smith Numbers(史密斯数)
Description 题目描述 While skimming his phone directory in 1982, Albert Wilansky, a mathematician of Leh ...
- POJ 1142:Smith Numbers(分解质因数)
Smith Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submiss ...
- poj 1142 Smith Numbers
Description While skimming his phone directory in 1982, Albert Wilansky, a mathematician of Lehigh U ...
- poj1142 Smith Numbers
Poj1142 Smith Numbers Smith Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13854 ...
- Smith Numbers - PC110706
欢迎访问我的新博客:http://www.milkcu.com/blog/ 原文地址:http://www.milkcu.com/blog/archives/uva10042.html 原创:Smit ...
- POJ 2182/暴力/BIT/线段树
POJ 2182 暴力 /* 题意: 一个带有权值[1,n]的序列,给出每个数的前面比该数小的数的个数,当然比一个数前面比第一个数小的个数是0,省略不写,求真正的序列.(拗口) 首先想到的是从前到后暴 ...
- UVA 10042 Smith Numbers(数论)
Smith Numbers Background While skimming his phone directory in 1982, Albert Wilansky, a mathematicia ...
随机推荐
- .net core Identity集成IdentityServer(2) 实现IprofileService接口在accesstoken中增加自定义claims
导读 1. 如何添加自定义的claims. 前请提要 目前我们拥有了三个web应用. localhost:40010, 验证服务器 localhost:40011, mvc客户端, 充当webapp请 ...
- c# 获取本机IP
/// <summary> /// 获取本机IP /// </summary> /// <returns></returns> public stati ...
- java-上转型对象&抽象类-学习记录
上转型对象: 如果B类是A类的子类(或间接子类),当用子类创建对象b并将这个对象的引用放到父类对象a中时,如: A a; a = new b() 或 A a;B b = new B();a = b; ...
- Compiler showing 'pi' symbol on error
Question: I was testing some code on Coliru, and I got a strange output. I went down the code and co ...
- 设计模式之适配器模式(Adapter)(6)
简介 在实际的开发过程中,由于应用环境的变化(例如使用语言的变化),我们需要的实现在新的环境中没有现存对象可以满足,但是其他环境却存在这样现存的对象.那么如果将“将现存的对象”在新的环境中进行调用呢? ...
- tfs 禁止多人签出
好久没用tfs了,忘了怎么设置了,记录下 编辑----->高级
- “一切都是消息”--iMSF(即时消息服务框架)之【请求-响应】模式(点对点)
MSF的名字是 Message Service Framework 的简称,由于目前框架主要功能在于处理即时(immediately)消息,所以iMSF就是 immediately Message S ...
- MIPS 安全相关paper阅读笔记
前言 论文来自 https://cyber-itl.org/2018/12/07/a-look-at-home-routers-and-linux-mips.html Linux_MIPS_mis ...
- eclipse下载教程
Eclipse 是一个开放源代码的.基于 Java 的可扩展开发平台. Eclipse 是 Java 的集成开发环境(IDE),当然 Eclipse 也可以作为其他开发语言的集成开发环境,如C,C++ ...
- WebSocket实现简单的在线聊天
SuperWebSocket在WebService中的应用 最开始使用是寄托在IIS中,发布之后测试时半个小时就会断开,所以改为WindowsService 1. 新建Windows服务项目[Test ...