题意:输入一个不超过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. docker安装fastdfs碰到storage的IP地址映射宿主地址问题

    一.概述 最近公司准备全面实施docker部署,解决每次项目实施安装部署环境工作量大问题,mysql5.7.oracle12c很顺利,在安装fastdfs时碰到storage的IP地址映射问题.服务器 ...

  2. 创建Dockerfile

    https://mp.weixin.qq.com/s?__biz=MzU0Mzk1OTU2Mg==&mid=2247483900&idx=1&sn=584962b8b6f24c ...

  3. Excel对某一列的数据插入处理,域名得出IP

    早期都是通过Excel做数据统计,对某一列的数据插入处理. 代码功能是从A列纯域名,将域名转换为IP,从域名A列得到IP写到B列. 代码 #!/usr/bin/python #coding:utf-8 ...

  4. skynet sproto 问题

    刚碰到一个小细节,纠结了半个小时 sproto的协议,request 和{ 必须有空格

  5. 【嵌入式硬件Esp32】(1)例程Hello World Example 注释

    /* Hello World Example This example code is in the Public Domain (or CC0 licensed, at your option.) ...

  6. Java基础:类文件结构及类加载

    Class文件结构 魔数 4bits 确定该文件是否是可接受的Class文件(0xCAFEBABE) 版本号 4bits 包括次版本号和主版本号 常量池 包括字面量(文本字符串,声明为final的常量 ...

  7. windows server 2012 r2 无法安装 .net 3.5

    服务器需安装SQL 2012 ,因需安装.net3.5,没有想到2012出于安全竟然不让手动安装,对于源文件也是把控比较严,折腾了好一会儿才解决问题 有参才一下powershell等安装命令,均失败. ...

  8. Ajax基本概念

    一. Ajax 1. 什么是ajax Ajax: asynchronous  javascript  and  xml (异步js和xml) 其是可以与服务器进行(异步/同步)交互的技术一. ajax ...

  9. [转载]SQL Server提权系列

    本文原文地址:https://www.cnblogs.com/wintrysec/p/10875232.html 一.利用xp_cmdshell提权 xp_cmdshell默认是关闭的,可以通过下面的 ...

  10. 什么是netty--通俗易懂

      一.Netty介绍 1.什么是netty Netty 是由 JBOSS 提供的一个 Java 开源框架.Netty 提供异步的.基于事件驱动的网络应用程序框架,用以快速开发高性能.高可靠性的网络 ...