1565: Vampire Numbers

时间限制: 3 Sec  内存限制: 128 MB
提交: 20  解决: 9
[提交][状态][讨论版]

题目描述

The number 1827 is an interesting number, because 1827=21*87, and all of the same digits appear on both sides of the `='. The number136948 has the same property: 136948=146*938.

Such numbers are called Vampire Numbers. More precisely, a number v is a Vampire Number if it has a pair of factors, a and b, wherea*b = v, and together, a and b have exactly the same digits, in exactly the same quantities, as v. None of the numbers va or b can have leading zeros. The mathematical definition says that v should have an even number of digits and that a and b should have the same number of digits, but for the purposes of this problem, we'll relax that requirement, and allow a and b to have differing numbers of digits, and v to have any number of digits. Here are some more examples:

126 = 6 * 21
10251 = 51 * 201
702189 = 9 * 78021
29632 = 32 * 926

Given a number X, find the smallest Vampire Number which is greater than or equal to X.

输入

There will be several test cases in the input. Each test case will consist of a single line containing a single integer X ( 10X1, 000, 000). The input will end with a line with a single `0'.

输出

For each test case, output a single integer on its own line, which is the smallest Vampire Number which is greater than or equal to X. Output no extra spaces, and do not separate answers with blank lines.

样例输入

10
126
127
5000
0

样例输出

126
126
153
6880
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set> using namespace std;
int vis[];
set<int> S;
void Init_set(){
for(int i = ; i <= ; i++)
for(int j = i; j <= /i; j++){
int m = i * j;
int tx = i, ty = j, tm = m;
while(tm) {vis[ tm% ]++; tm /= ;}
while(tx) {vis[ tx% ]--; tx /= ;}
while(ty) {vis[ ty% ]--; ty /= ;}
bool is = true;
for(int i = ; i < ; i++)
if(vis[i]) is = false, vis[i] = ;
if(is) S.insert( m );
}
}
int main(){
int x;
Init_set();
while(scanf("%d", &x) == && x){
printf("%d\n", *S.lower_bound( x ));
}
}
 

最新文章

  1. ReactNative中iOS和Android的style分开设置教程
  2. HTML &lt;a&gt; 标签的 target 属性
  3. Python 中的枚举类型~转
  4. MFC如何隐藏RibbonBar的QAT QuickAccessToolBar(快速访问工具栏)
  5. [deviceone开发]-动画示例源码
  6. 初识Go
  7. java File.mkdirs和mkdir区别
  8. PostgreSQL 一主两备节点(两备节点为同步节点)故障恢复
  9. 《openstack 和hadoop的区别是什么?》
  10. virtualbox 创建com对象失败
  11. 如何使用Instruments诊断App(Swift版):起步-b
  12. 【C++实现】HeadFirst策略模式设计模式
  13. Freertos之系统配置
  14. yii2 Nav::widget() 和 Menu::widget()
  15. sequelizejs中文文档(一)
  16. datatable 参数详细说明
  17. Java作业-网络编程
  18. 虚拟机有QQ消息时宿主机自动弹窗提示
  19. CPU温度的实现
  20. swift 头尾式动画

热门文章

  1. shell练习--关于关联数组自增统计判断的学习
  2. Java面试题系列(六)优化tomcat配置
  3. 数据:ContentResolver类
  4. 字符串:StringBuilder()
  5. linux socket设置阻塞与非阻塞
  6. 浅谈 Catalan number——卡特兰数
  7. pyinstaller打包的exe太大?你需要嵌入式python玄学 拓展篇
  8. android图片的缩放、圆角处理
  9. HBase调优案例(一)——建表长时间等待最后失败
  10. 超过 150 个最佳机器学习,NLP 和 Python教程