题意:给你两个数p和x,然后让你找出一个长度为p的数,把它的最后移到最前面之后得到的数是原来数字的x倍,有很多这样的数取最小。

思路:枚举最后一位,然后就可以推出整个的一个数,然后比较得到的数的第一个数字和枚举的数字是否相等既可以。

 #include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std; int p,x;
char str[]; int main()
{
scanf("%d%d",&p,&x);
bool flag=false;
for(int i=; i<=; i++)
{
int m=i;
int c=;
int y=i;
str[]=m+'';
for(int j=; j<=p; j++)
{
int cc=(y*x+c)/;
y=(y*x+c)%;
str[j]=y+'';
c=cc;
}
if(y==m&&str[p-]!=''&&c==)
{
flag=true;
for(int k=p-; k>=; k--)
{
printf("%c",str[k]);
}
printf("\n");
break;
}
}
if(!flag) printf("Impossible\n");
return ;
}

cf B Very Beautiful Number的更多相关文章

  1. Codeforces 55D Beautiful Number

    Codeforces 55D Beautiful Number a positive integer number is beautiful if and only if it is divisibl ...

  2. zoj Beautiful Number(打表)

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2829 题目描述: Mike is very lucky, as ...

  3. beautiful number 数位DP codeforces 55D

    题目链接: http://codeforces.com/problemset/problem/55/D 数位DP 题目描述: 一个数能被它每位上的数字整除(0除外),那么它就是beautiful nu ...

  4. zoj 2829 Beautiful Number

    Beautiful Number Time Limit: 2 Seconds      Memory Limit: 65536 KB Mike is very lucky, as he has two ...

  5. hdu 5179 beautiful number

    beautiful number 问题描述 令 A = \sum_{i=1}^{n}a_i * {10}^{n-i}(1\leq a_i \leq 9)A=∑​i=1​n​​a​i​​∗10​n−i​ ...

  6. Beautiful Number

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2829 Beautiful Number Time Limit: 2 Sec ...

  7. HDU 5179 beautiful number (数位dp / 暴力打表 / dfs)

    beautiful number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  8. Codeforces 55D Beautiful Number (数位统计)

    把数位dp写成记忆化搜索的形式,方法很赞,代码量少了很多. 下面为转载内容:  a positive integer number is beautiful if and only if it is  ...

  9. CF#231DIV2:A Good Number

    Let's call a number k-good if it contains all digits not exceeding k (0, ..., k). You've got a numbe ...

随机推荐

  1. 基于Visual C++2012拆解世界五百强面试题--题3

    请用C语言实现 输入N,打印N*N矩阵 比如 N = 3, 打印: 1 2 3 8 9 4 7 6 5 N = 4, 打印 1   2    3   4 12  13   14  5 11  16   ...

  2. Swift学习笔记八:枚举

    1. 枚举语法      1)枚举的定义 使用enum关键词而且把它们的整个定义放在一对大括号内: enum SomeEumeration { // enumeration definition go ...

  3. 利用 SysRq 键排除和诊断系统故障

    说白了,SysRq手动触发而不用命令, /proc/sysrq-trigger 这个是通过命令接口 实验:LINUX窗口下 ,CTRL+ALT+F1,切换到TTY1,在文本模式下,按下 ALT+Sys ...

  4. [转] JavaScript 原型理解与创建对象应用

    这段时间把之前的 JavaScript 的笔记复习了一遍,又学习了一些新的内容,所以把自己的学习笔记加上个人理解在这里总结一下,并提供一个简单的应用示例,希望能帮助一些刚入门的朋友.主 要参考< ...

  5. Java基础知识强化之集合框架笔记21:数据结构之 数组 和 链表

    1. 数组 2. 链表

  6. 使用SqlAlchemy时如何方便的取得dict数据、dumps成Json

    使用Sqlalchemy可以方便的从数据库读取出python对象形式的数据(吐槽:说实话对象形式也没多方便,还不如我之前从关系型数据库直接读取出dict形式的数据用起来方便,具体参见我以前的文章htt ...

  7. Bginfo软件在域的部署和应用

    在企业的IT管理中,很多用户都不知道怎么去查看自己计算机的IP地址.登陆帐户.而对于网络管理人员来说,他们可能需要知道用户在域中登录的一些信息,如那些用户登录过,在什么时间登录,IP和MAC地址是多少 ...

  8. Python中sys.argv[]的用法

    类似bash中的$0, $1, $2... sys.argv[0]:文件名 sys.argv[1]:第一个参数 sys.argv[2]:第二个参数 import sys print "The ...

  9. 导出到excel

    /// <summary> /// 导出 /// </summary> /// <param name="table">数据表</para ...

  10. 未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”提供程序。

    错误: 解决方案: 1."设置应用程序池默认属性"/"常规"/"启用32位应用程序",设置为 true. 如下图所示:(已测试,好使) 方法 ...