Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may assume that n is not greater than 200 and there is a corresponding m containing no more than 100 decimal digits.

Input The input file may contain multiple test cases. Each line contains a value of n (1 ≤ n ≤ 200). A line containing a zero (0) terminates the input.

Output For each value of n in the input print a line containing the corresponding value of m. The decimal representation of m must not contain more than 100 digits. If there are multiple solutions for a given value of n, any one of them is acceptable.

Sample Input 2 6 19 0

Sample Output

10

100100100100100100

111111111111111111

个人心得:这题开始没看懂,原来是求所求数的倍数,但这个倍数只由0,1组成,有俩种版本,一个是longlong直接过,这个在数据较多的时候不容易过,

先说下longlong吧,就是从1开始深搜,有2种方向,一是乘以10,二是乘以10再加1,这个简单深搜还是比较好实现的。

 #include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
#include<algorithm>
using namespace std;
int n,flag;
unsigned long long ans;
void dfs(unsigned long long x,int y)
{
if(y>) return ;
if(x%n==)
{
flag=;
ans=x;
return; }
else
{for(int i=;i<;i++)
dfs(*x+i,y+);
}
if(flag) return; }
int main()
{
unsigned long long x;
while(cin>>n)
{
if(n==) break;
x=;
flag=;
dfs(x,);
cout<<ans<<endl; }
return ; }

再看一下数组存储的代码,他这个涉及到的知识点真的不知道,每次得到新数都进行取余再将这个数放入数组里,这样就不会数据溢出了,一开始想这么做怕担心

数据会溢出。

 #include <iostream>

 using namespace std;

 int n, t, a[], ac,l;

 void dfs(int c, int s)

 {

          if(s==)//如果余数为0,择停止递归

          {

                    ac = ;//表示已经找到结果

                    l=c;//给数组的长度赋值

          }

          else if(c < )//在深度100范围内进行递归

          {

                    if(ac==)//还没找到结果,进行递归运算

                    {

                             a[c] = ;//尝试下一位放1

                             dfs(c + , (s *  + ) % n);

                    }

                    if(ac==)

                    {

                             a[c] = ;

                             dfs(c + , (s * ) % n);

                    }

          }

 }

 int main()

 {

          while(cin>>n,n)

          {

                    a[] = , ac = ;//初始化

                    dfs(, );

                    for(int i=;i<l;i++) cout<<a[i];//根据递归得到的结果,进行输出

                    cout<<endl;

          }

          return ;

 }

最新文章

  1. Jenkins部署配置简介
  2. display:inline; display:block;
  3. Ubuntu之root权限的获取
  4. VMware设置共享文件夹
  5. Cocoa Touch的3种类的交流方式delegate/target/notification
  6. javascript应用:页面解析list和map封装后的json数据
  7. python3编码问题
  8. 状态压缩dp入门
  9. ngixn配置
  10. Leetcode_198_House Robber
  11. NTT板子
  12. 【细小碎的oi小知识点总结贴】不定时更新(显然也没人看qwq)
  13. 微信小程序开发指南
  14. Python基础-python数据类型之列表(四)
  15. Spring与MyBatis面试
  16. Window10激活
  17. 【python-proxy by sockets5】pysocks
  18. 使用web api开发微信公众号,调用图灵机器人接口(二)
  19. 模板:快速傅里叶变换(FFT)
  20. CF593C Beautiful Function 构造

热门文章

  1. python 课堂笔记-for语句
  2. mongodb简单用法
  3. 纯代码编写qt登录界面(转)
  4. OPENGL ES2.0如何不使用glActiveTexture而显示多个图片
  5. 每日练习level-7
  6. 摊铺机基本参数介绍(鼎盛天工WTD9501A)
  7. R中的数据重塑函数
  8. 自己的第一个MapReduce程序
  9. Unity发布安卓后,安卓输入键盘字体白色
  10. INSPIRED启示录 读书笔记 - 第8章 巴顿将军的忠告