[暴力分治]POJ 1142 Smith Numbers
来源:互联网 发布:php date格式化输出 编辑:程序博客网 时间:2024/06/01 08:32
题目链接 : http://poj.org/problem?id=1142
题目大意 : 给定一个N,求一个大于N的最小的Smith Numbers,Smith Numbers是一个合数,且分解质因数之后上质因子每一位上的数字之和 等于 其本身每一位数字之和
思路 :分解质因数的时间复杂度是log,求一个数各个位数上的数字之和时间复杂度是位数,可以直接暴力,递归写非常美观
code:
#include <cstdio>#include <iostream>#include <algorithm>#include <cstring>#include <cmath>using namespace std;#define foru(i, a, b) for (int i=a; i<=b; i++)#define ford(i, a, b) for (int i=a; i>=b; i--)#define N 200#define M 11000int n;bool pri(int x){ foru(i, 2, sqrt(x)) if (x%i == 0) return 0; return 1;}int sum(int x){ if (! x) return x; return x%10 + sum(x/10);}int get(int x){ if (pri(x)) return sum(x); ford(i, sqrt(x), 2) if (x%i == 0 && pri(i)) return get(i) + get(x/i);}int main(){ // freopen("P.txt", "r", stdin); while (scanf("%d", &n) != EOF ){ if (! n) break; while (n ++){ if (!pri(n) && sum(n) == get(n)) break; } printf("%d\n", n); } return 0;}
0 0
- [暴力分治]POJ 1142 Smith Numbers
- [POJ]1142-Smith Numbers [暴力][容斥]
- POJ 1142 Smith Numbers
- POJ 1142 Smith Numbers
- poj 1142 Smith Numbers
- poj 1142 Smith Numbers
- Poj 1142 Smith Numbers
- poj 1142 Smith Numbers
- POJ 1142 Smith Numbers
- poj 1142 Smith Numbers
- POJ-----1142---Smith Numbers
- poj 1142 Smith Numbers 筛法
- POJ 1142 Smith Numbers 笔记
- ZOJ 1133 Smith Numbers && POJ 1142 Smith Numbers
- Smith Numbers 素数打表+暴力+求素因子+poj
- zoj 1133 || poj 1142 Smith Numbers
- ZOJ 1133 & POJ 1142 Smith Numbers
- UVa 10042 && POJ 1142 - Smith Numbers
- SSO之CAS基础及应用视频教程(1)
- ToolUtil类
- ubuntu安装jdk全过程(仅供参考)
- W7100A与W7100的差别
- Cracking the coding interview--Q20.7
- [暴力分治]POJ 1142 Smith Numbers
- RCC 2014 Warmup div2 D--状压dp
- Django Models
- Menu
- test
- linux kernel 配置方法及其配置系统
- socket编程原理 .
- php除数取整
- android布局LinearLayout的隐藏和显示