【HDU】 1333 Smith Numbers
来源:互联网 发布:js请求url获取返回值 编辑:程序博客网 时间:2024/06/13 04:22
Smith Numbers
题目链接
- Smith Numbers
题目大意
现在我们定义一种数叫Smith Numbers,这种数能被分解成若干个(>1)质数的乘积且数位和相同,现在让你求比n大的最小的Smith Numbers是哪个。
题解
这个题本来直接暴力就行了的…结果中间传参传错了WA好久…
代码
#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>#include <cmath>#define maxn 100000000using namespace std;int n,tab[1000005],vis[1000005],h,cnt[1000005];int sum(int a){ int ans=0; while (a) { ans+=a%10; a/=10; } return ans;}void dealtab(int high){ h=0; for (int i=2;i<=high;i++) if (!vis[i]) { int j=i; cnt[h]=sum(i); tab[h++]=i; while (j<=high) { vis[j]=1; j+=i; } }}bool check_(int p){ for (int i=0;tab[i]*tab[i]<=p;i++) if (p%tab[i]==0) return 0; return 1;}int main(){ dealtab(100000); while(scanf("%d",&n),n!=0) { for (int i=n+1;i<maxn;i++) { if (check_(i)) continue; int x1=sum(i),x2=0,t=i; for (int j=0;tab[j]*tab[j]<=t;j++) { int x3=cnt[j]; if (t==1) break; while (t%tab[j]==0) { t/=tab[j]; x2+=x3; } } if (t>1) x2+=sum(t); if (x1==x2) { printf("%d\n",i); break; } } } return 0;}
0 0
- hdu 1333 Smith Numbers
- 【HDU】 1333 Smith Numbers
- hdu 1333 Smith Numbers(暴力思路)
- hdu-1333 Smith Number
- Smith Numbers
- Smith Numbers
- Smith Numbers
- POJ 1142 Smith Numbers
- 1027: Smith Numbers
- zoj 1133 Smith Numbers
- zoj 1133 - Smith Numbers
- uva 10042 smith numbers
- POJ 1142 Smith Numbers
- poj 1142 Smith Numbers
- Smith Numbers hdu1333 素数
- poj 1142 Smith Numbers
- Poj 1142 Smith Numbers
- hdu1333/poj1142-Smith Numbers
- quick lua-binding使用详解
- VS搭载SQL 常用语句 (1)
- APIStore使用例子(获取易源笑话)
- javascript和python写的选择排序算法
- 打开保存对话框(saveFileDialog和openFileDialog控件)
- 【HDU】 1333 Smith Numbers
- 简单dp
- Ubuntu10.04下安装tftp服务器
- Java基础-静态导入:static import
- 判断两条线段是否相交
- 第13周实践项目-立体族类共有的抽象类
- NYOJ 456 邮票分你一半
- 封装
- Lombok - 消除冗长的 java 代码