题意:输入一个不超过200的数 n,然后求得一个数字k,数字满足:能被n整除,每一位只有0,1。这样的数字k会有很多个,然以输出一个就可以。

注意unsigned __int64的范围,-(10^19)~(10^20)所以步数不能超过19次。 (摘)

附:同余模定理:

(a*b)%n = (a%n *b%n)%n;

(a+b)%n = (a%n +b%n)%n;

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std; int n,flag; void DFS(int step,long long num)
{
if(step== || flag) return; //64位 最多加19步
if(num%n==)
{
cout<<num<<endl;
flag=; //如果得到一个数了,就可以全退出
return;
}
DFS(step+,num*);
DFS(step+,num*+);
} int main()
{
ios::sync_with_stdio(false);
while(cin>>n && n!=)
{
flag=;
DFS(,);
}
}

Find The Multiple (DFS递归)的更多相关文章

  1. POJ 1321-棋盘问题(DFS 递归)

    POJ 1321-棋盘问题 K - DFS Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I6 ...

  2. 数据结构作业——图的存储及遍历(邻接矩阵、邻接表+DFS递归、非递归+BFS)

    邻接矩阵存图 /* * @Author: WZY * @School: HPU * @Date: 2018-11-02 18:35:27 * @Last Modified by: WZY * @Las ...

  3. Timus 1329. Galactic History。LCA最近公共祖先或dfs递归离线处理!

    1329. Galactic History 比赛的时候看到学弟A了这题然后跟榜做,结果在LCA的道路上一去不复返,这个题是很像LCA求最近公共祖先的,不过三个人都没学过LCA,只能拿着资料看着像然后 ...

  4. [LeetCode] Combinations (bfs bad、dfs 递归 accept)

    Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For exampl ...

  5. 图的DFS递归和非递归

    看以前写的文章: 图的BFS:http://www.cnblogs.com/youxin/p/3284016.html DFS:http://www.cnblogs.com/youxin/archiv ...

  6. 深度优先搜索(DFS)递归形式改为非递归形式

    DFS将递归改为非递归这个方法的需求来自于一道三维积木组合的题目,还在苦苦调试中,暂且不提. 普通的认识对于递归向非递归的转化无非是使用栈,但是结合到深度搜索如何将栈很好利用,如何很好保存现场,都不是 ...

  7. 八皇后问题 dfs/递归

    #include <bits/stdc++.h> using namespace std; const int maxn = 55; int ans=0; int vis_Q[maxn]; ...

  8. (N叉树 DFS 递归 BFS) leetcode 559. Maximum Depth of N-ary Tree

    Given a n-ary tree, find its maximum depth. The maximum depth is the number of nodes along the longe ...

  9. (二叉树 DFS 递归) leetcode 112. Path Sum

    Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all ...

随机推荐

  1. Dotmemory 内存分析工具的操作手册

    教程一.开始学习dotmemory 在本教程中,我们将学习如何运行dotMemory内存快照.此外,我们将简要地看看dotMemory的用户界面和基本分析的概念.考虑dotMemory本教程作为起点 ...

  2. 原生js 实现better-scroll效果,饿了么菜单内容联动,即粘即用

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  3. java实现邮箱发送邮件功能

    邮箱验证是一个很常见的功能了,基本上每个网站都会用的到,java也有专门的jar来处理邮件发送等服务,这里只是简单的实现一下发送邮件的功能,具体jar包就不再提供了,我会把所有需要引用的包都贴出来,方 ...

  4. 共阳极RGB LED二极管

    1)RGB LED二极管有四个引脚,它把3个普通led被封装在其内部,这三个led颜色分别为红.绿.蓝三种颜色,通过控制各个LED的亮度,你可以混合出几乎任何你想要的颜色,如下图: 2)RGB LED ...

  5. input的小技巧 清除自动记录

    input 消除自动记忆功能 在html里就可以直接清除了<input type="text" autocomplete="off"> input ...

  6. django 相关配置(pycharm)

      第二步  

  7. Linux安装JDK,Tomcat,Mysql+部署项目

    安装VMWare虚拟机 下载地址(http://www.onlinedown.net/soft/2062.htm) 安装步骤很简单(除了选择安装路径),傻瓜式安装 同意协议 选择安装路径 安装 完成 ...

  8. vue设置input不可编辑切换

    html: <Input name="a" v-model="formValidate.coName" placeholder="请输入姓名&q ...

  9. 利用 nodejs 解析 m3u8 格式文件,并下 ts 合并为 mp4

    利用 nodejs 解析 m3u8 格式文件,并下 ts 合并为 mp4 以前看视频的时候,直接找到 video标签,查看视频地址,然后下载下来.. 后来发现,好多 video 标签打开元素审查,如下 ...

  10. java -jar 参数前后位置说明

    springboot项目启动的时候可以直接使用java -jar xxx.jar这样.下面说说参数的一些讲究 1.-DpropName=propValue的形式携带,要放在-jar参数前面 eg:ja ...