A - Smith Numbers POJ
4937775= 3*5*5*65837
The sum of all digits of the telephone number is 4+9+3+7+7+7+5= 42,and the sum of the digits of its prime factors is equally 3+5+5+6+5+8+3+7=42. Wilansky was so amazed by his discovery that he named this kind of numbers after his brother-in-law: Smith numbers.
As this observation is also true for every prime number, Wilansky decided later that a (simple and unsophisticated) prime number is not worth being a Smith number, so he excluded them from the definition.
Wilansky published an article about Smith numbers in the Two Year College Mathematics Journal and was able to present a whole collection of different Smith numbers: For example, 9985 is a Smith number and so is 6036. However,Wilansky was not able to find a Smith number that was larger than the telephone number of his brother-in-law. It is your task to find Smith numbers that are larger than 4937775!
Input
Output
Sample Input
4937774
0
题目大意:
给你一个数,求大于这个数字并满足以下条件的最小值:
条件:数字的各个位置加起来与用质数拆分该数字后得到的数字的各个位置之和相等 4937775= 3*5*5*65837
暴力模拟就可以啦 首先要知道质数拆分,然后将得到的每个数字的各个位置相加相等。如果与原数字相等的话说明找到啦!
#include<iostream>
#include<cstdio>
using namespace std; int check(int x){//由于数字范围太大,不能打表,只能这样一步一步来
for(int i=;i*i<=x;i++){
if(x%i==) return ;
}
return ;
} int f2(int x){
int sum=;
while(x){
sum+=x%;
x=x/;
}
return sum;
}
int f(int x){
int sum=;
for(int i=;i*i<=x;i++){//拆分
if(x%i==){
int ans=;
if(i<)
{
while(x%i==){
ans++;
x=x/i;
}
sum+=i*ans;
}
else {
int s=f2(i);
while(x%i==){
ans++;
x=x/i;
}
sum+=s*ans;
}
}
}
if(x>) sum+=f2(x);
return sum;
}
int main(){
int n;
while(scanf("%d",&n)!=EOF&&n){
for(int i=n+;;i++){
if(check(i)==){
if(f2(i)==f(i)){
printf("%d\n",i);
break;
} }
}
}
return ;
}
A - Smith Numbers POJ的更多相关文章
- Smith Numbers POJ - 1142 (暴力+分治)
题意:给定一个N,求一个大于N的最小的Smith Numbers,Smith Numbers是一个合数,且分解质因数之后上质因子每一位上的数字之和 等于 其本身每一位数字之和(别的博客偷的题意) 思路 ...
- Smith Numbers POJ - 1142 暴力递归枚举
题意: 给你一个数x,把这个分解成素数之积(假设是x1*x2*x3),如果 x的每一数位的和 等于 x1每一数位的和加上x2每一数位的和加上x3每一数位的和,那么他就是题目要找的数 示例: ...
- 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 1142:Smith Numbers(分解质因数)
Smith Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submiss ...
- Smith Numbers - PC110706
欢迎访问我的新博客:http://www.milkcu.com/blog/ 原文地址:http://www.milkcu.com/blog/archives/uva10042.html 原创:Smit ...
- poj1142 Smith Numbers
Poj1142 Smith Numbers Smith Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13854 ...
- UVA 10042 Smith Numbers(数论)
Smith Numbers Background While skimming his phone directory in 1982, Albert Wilansky, a mathematicia ...
- Smith Numbers(分解质因数)
Smith Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14173 Accepted: 4838 De ...
随机推荐
- C++中decltype(*)作为模板实参时的隐藏问题
在函数模板中使用智能指针时,可能会希望根据指针的类型推导出指针引用的对象类型作为模板参数,于是写出以下代码: shared_ptr<decltype(*objPtr)>(objPtr); ...
- IDEA编写 Scala时没有语法检查和错误提示
#问题描述 在IDEA中写scala程序时,一些明显的语法错误不进行检查,没有像写Java时的红线什么的,当编译运行时,编译失败. https://blog.csdn.net/weizheng1000 ...
- [Flink] Flink的waterMark的通俗理解
导读 Flink 为实时计算提供了三种时间,即事件时间(event time).摄入时间(ingestion time)和处理时间(processing time). 遇到的问题: 假设在一个5秒的T ...
- 记录一些服务端术语和搭建web服务器
菜单快捷导航 服务端常用术语 搭建web服务器和配置虚拟主机 记录一些服务端方面的常用术语 1.CS架构和BS架构 1.1 CS架构 CS(Client/Server),基于安装包类型的桌面或手机软件 ...
- Github桌面版使用方式(MAC)
Github是一个流行的代码管理网站,同时也是全球最大的同性交友网站(滑稽).Github网页上你可以自由地托管自己的项目,也可以fork别人的项目过来玩耍,非常之方便,今天笔者就来介绍一下githu ...
- ScheduledThreadPoolExecutor之remove方法
之前用定时任务的线程池,设置了个任务,但是突然今天产品说,某些个操作需要中断某些任务(如果任务还没有执行),使其不能再到点执行了.于是查了API果然有这样一个方法. 一看API,需要移除的是一个Run ...
- Spring的IOC操作
Spring的IOC操作 把对象的创建交给spring ioc操作两个部分 (1)ioc的配置文件方式 (2)ioc基于注解的方式 IOC 的底层原理 1.ioc底层原理使用技术 (1)xml配置文件 ...
- Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty messa
1.git提交的时候遇到: # Please enter the commit message for your changes. Lines starting with '#' will be ig ...
- java/php DES/CBC/PKCS5Padding加密解密算法实现过程
先看java代码 public static String encrypt(String message, String key) throws Exception { Cipher cipher = ...
- MyBatis(十):Mybatis缓存的重要内容
本文是按照狂神说的教学视频学习的笔记,强力推荐,教学深入浅出一遍就懂!b站搜索狂神说或点击下面链接 https://space.bilibili.com/95256449?spm_id_from=33 ...