cf B Very Beautiful Number
题意:给你两个数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的更多相关文章
- Codeforces 55D Beautiful Number
Codeforces 55D Beautiful Number a positive integer number is beautiful if and only if it is divisibl ...
- zoj Beautiful Number(打表)
题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2829 题目描述: Mike is very lucky, as ...
- beautiful number 数位DP codeforces 55D
题目链接: http://codeforces.com/problemset/problem/55/D 数位DP 题目描述: 一个数能被它每位上的数字整除(0除外),那么它就是beautiful nu ...
- zoj 2829 Beautiful Number
Beautiful Number Time Limit: 2 Seconds Memory Limit: 65536 KB Mike is very lucky, as he has two ...
- hdu 5179 beautiful number
beautiful number 问题描述 令 A = \sum_{i=1}^{n}a_i * {10}^{n-i}(1\leq a_i \leq 9)A=∑i=1nai∗10n−i ...
- Beautiful Number
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2829 Beautiful Number Time Limit: 2 Sec ...
- HDU 5179 beautiful number (数位dp / 暴力打表 / dfs)
beautiful number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- Codeforces 55D Beautiful Number (数位统计)
把数位dp写成记忆化搜索的形式,方法很赞,代码量少了很多. 下面为转载内容: a positive integer number is beautiful if and only if it is ...
- 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 ...
随机推荐
- Android 颜色渲染(九) PorterDuff及Xfermode详解
版权声明:本文为博主原创文章,未经博主允许不得转载. Android 颜色渲染(九) PorterDuff及Xfermode详解 之前已经讲过了除ComposeShader之外Shader的全部子类 ...
- 读TIJ -1 对象入门
<Thinking In Java·第 1 章对象入门> 第 1 章约20页,是对面向对象的程序设计(OOP)的一个综述. 依照其前言所述: "当中包含对"什么是对象& ...
- 计算机体系结构 -内存优化vm+oom
http://www.cnblogs.com/dkblog/archive/2011/09/06/2168721.htmlhttps://www.kernel.org/doc/Documentatio ...
- spring mvc DispatcherServlet详解之四---视图渲染过程
整个spring mvc的架构如下图所示: 现在来讲解DispatcherServletDispatcherServlet的最后一步:视图渲染.视图渲染的过程是在获取到ModelAndView后的过程 ...
- 关于Sublime Text3 pyV8无法加载的问题
昨天切换到sublime text 3 安装 emmet插件 不起作用 提示 pyv8 无法加载 手动下载安装解决 问题描述 PyV8 Binaries Archive of pre-compi ...
- RHEL7安装配置TigerVNC
TigerVNC使用非加密的链接,默认会被firewalld blocked 掉,想要 vnc正常工作就需要让firewalld开放相应的端口才行. vnc默认的端口号为5900,而每个vnc win ...
- Bootstrap V3使用Tab标签
Bootstrap V3使用Tab标签 >>>>>>>>>>>>>>>>>>>> ...
- Spire.Barcode好用的条码生在组件
由于项目的需要,今天在网上找了一下条码的组件,发现了一个简单易用的组件,使用简单,几句代码就搞定了.
- SQLSERVER 触发器 将一个服务器上的数据库中数据插入到另一个服务器上的数据库中怎么做
首先要执行 sp_addlinkedserver '服务器ip' 然后开始写语句 insert into ip.库名字.dbo.table select * from iserted
- Jmeter软件测试1--webservice测试
写在前言 程序猿一枚,原本就是负责安安静静的撸代码,后来公司让兼任下测试的工作,还得照顾下面的几个测试兄弟,无奈本人毫无软件测试理论知识,下面的测试兄弟也是初级水平,又面临公司要求做webservic ...