Smith Numbers POJ - 1142 暴力递归枚举
题意:
给你一个数x,把这个分解成素数之积(假设是x1*x2*x3),如果 x的每一数位的和 等于 x1每一数位的和加上x2每一数位的和加上x3每一数位的和,那么他就是题目要找的数
示例:
4937775 = 3 * 5 * 5 * 65837
电话号码的所有数字的和为4+9+3+7+7+7+5= 42,其质因数的数字的和为3+5+5+6+5+ 5+8+3+7=42。
题解:
暴力,具体见代码
代码:
1 #include<stdio.h>
2 #include<string.h>
3 #include<iostream>
4 #include<algorithm>
5 #include<math.h>
6 using namespace std;
7 typedef long long ll;
8 const int maxn=100005;
9 bool isprim(int x)
10 {
11 for(int i=2;i<=sqrt(x);++i)
12 {
13 if(x%i==0) return 0;
14 }
15 return 1;
16 }
17 int get_sum(int x)
18 {
19 int ans=0;
20 while(x)
21 {
22 ans+=x%10;
23 x/=10;
24 }
25 return ans;
26 }
27 int digui(int x)
28 {
29 int temp=sqrt(x);
30 if(isprim(x))
31 return get_sum(x);
32 else
33 {
34 for(int i=2;i<=temp;++i) //这个for循环作用就是找一个x的因子
35 {
36 if(x%i==0)
37 return digui(i)+digui(x/i);
38 }
39 }
40 }
41 int main()
42 {
43 int n;
44 while(~scanf("%d",&n) && n)
45 {
46 while(n++)
47 {
48 if(!isprim(n) && digui(n)==get_sum(n))
49 break;
50 }
51 printf("%d\n",n);
52 }
53 return 0;
54 }
Smith Numbers POJ - 1142 暴力递归枚举的更多相关文章
- Smith Numbers POJ - 1142 (暴力+分治)
题意:给定一个N,求一个大于N的最小的Smith Numbers,Smith Numbers是一个合数,且分解质因数之后上质因子每一位上的数字之和 等于 其本身每一位数字之和(别的博客偷的题意) 思路 ...
- 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 ...
- POJ 1753 位运算+枚举
题意: 给出4*4的棋盘,只有黑棋和白棋,问你最少几步可以使棋子的颜色一样. 游戏规则是:如果翻动一个棋子,则该棋子上下左右的棋子也会翻一面,棋子正反面颜色相反. 思路: 都是暴搜枚举. 第一种方法: ...
- 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,省略不写,求真正的序列.(拗口) 首先想到的是从前到后暴 ...
- poj1142 Smith Numbers
Poj1142 Smith Numbers Smith Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13854 ...
随机推荐
- ctfhub技能树—sql注入—布尔盲注
打开靶机 查看页面信息 开始试验,查看返回信息 此题存在一个问题,如果没有数据,也是返回query_success 如此一来,就无法使用and组合进行注入,在看了其他大佬的解题过程后,知道了可以使用& ...
- oracle释放空间到OS
测试: 建表空间 CREATE TABLESPACE TESTTBS DATAFILE '/oradata01/dfhdb/testtbs01.dbf' SIZE 2G; 在表空间上建表 CREATE ...
- Windows系统使用运行框运行程序
配置步骤 1. 在非系统盘创建一个新文件夹,自定义名称.将需要使用运行框启动的程序或文件放入文件夹,并将其更改为自己容易记忆的名称 2. 创建环境变量 右击 "此电脑" → &qu ...
- Flutter 自定义列表以及本地图片引用
前言 上篇关于Flutter的文章总结了下标签+导航的项目模式的搭建,具体的有需要的可以去看看Flutter分类的文章,这篇文章我们简单的总结一下关于Flutter本地文件引用以及简单的自定义List ...
- kafka(二)基本使用
一.Kafka线上集群部署方案 既然是集群,那必然就要有多个Kafka节点机器,因为只有单台机器构成的kafka伪集群只能用于日常测试之用,根本无法满足实际的线上生产需求. 操作系统: kafka由S ...
- 1.5V转5V的最少电路的芯片电路图
PW5100满足1.5V转5V的很简洁芯片电路,同时达到了最少的元件即可组成DC-DC电路1.5V转5V的升压转换器系统. PW5100在1.5V转5V输出无负载时,输入效率电流极低,典型值10uA. ...
- PAT Advanced 1004 Counting Leaves
题目与翻译 1004 Counting Leaves 数树叶 (30分) A family hierarchy is usually presented by a pedigree tree. You ...
- linux设备
设备初始化时同样要执行一个device_register函数,该函数传入一个struct device *类型的指针,因此要定义一个struct device类型的变量作为我们的设备. struct ...
- 超微服务器重置ipmi登录密码
超微服务器的ipmi登录密码不对,需要重置但是bios内并没有找到可以设置的选项. 以下是解决办法: 安装IPMITOOLyum install ipmitool -y 执行以下命令加载模块:modp ...
- postgres多知识点综合案例
使用到的知识点: 1.使用with临时存储sql语句,格式[with as xxx(), as xxx2() ]以减少代码: 2.使用round()取小数点后几位: 3.使用to_char()将时间格 ...