• 【POJ】1426 Find The Multiple


    题目链接http://poj.org/problem?id=1426

    题意:给定一个正整数n,找一个比n大且能只由01构成的且能够被n整除的数。

    题解:这个就是在后面添0和添1小心试探。一定要是添0不成功再去添1。

    代码:

     1 #include<iostream>
     2 #include<cstdio>
     3 using namespace std;
     4 #define ll long long 
     5 
     6 int flag;  
     7 int n;  
     8 
     9 int dfs(ll s,int step){  
    10     if(flag == 1 || step == 19)  
    11         return 0;  
    12     else if( s % n == 0){  
    13         printf("%lld
    ",s);  
    14         flag = 1;  
    15         return 1;  
    16     }  
    17     else{  
    18         if( !dfs( s*10 , step+1 ))  
    19             dfs(s*10 + 1, step+1);  
    20     }  
    21 }  
    22 int main(){  
    23     while(scanf("%d",&n)!= EOF && n){
    24         flag = 0;
    25         dfs(1,0);
    26     }
    27 
    28     return 0;  
    29 }   
  • 相关阅读:
    settTimeout vs setInterval
    JS继承
    JS创建对象
    原型链
    开始学习python的感受
    Problem 29
    Python 查看关键字
    Problem 21
    Problem 34
    Problem 42
  • 原文地址:https://www.cnblogs.com/Asumi/p/9696952.html
Copyright © 2020-2023  润新知