注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

zjushuiping

追求的只是心中的那一份宁静!

 
 
 

日志

 
 

poj 1426  

2010-08-16 16:48:31|  分类: ACM/ICPC |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
Find The Multiple
Time Limit: 1000MS
Memory Limit: 10000K
Total Submissions: 7103
Accepted: 2952
Special Judge

Description

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 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

Source

Dhaka 2002


#include <cstdlib>
#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;
int n;
int data[101];

int judge(int d[])//判断是否有data(mod n)==0
{
    int c=0;
    int i;
    for(i=0;i<=100;i++)
    if(d[i])
    break;
    if(i>100)
    return 0;
    c=d[i];
    c%=n;
    for(i=i+1;i<=100;i++)
    {
                        c*=10;
                        c+=d[i];
                        c%=n;
    }
    if(c==0)
    return 1;
    else
    return 0;
}


void output()//输出符合要求的data
{
    int i;
    for(i=1;i<=100;i++)
     if(data[i])
     break;
     for(i;i<=100;i++)
     cout<<data[i];
     cout<<endl;
}
int dfs(int s)
{
    int i,j,k;
    if(judge(data))
    {output();return 1;}
   
    for(i=s;i<=100;i++)
    {if(data[i])
     continue;
    
    
                       data[i]=1;
                       if(dfs(i+1))
                       return 1;
                       data[i]=0;
    }
   
    return 0;
}
                      
                      
                      
                      
                      
                      
                      
   


int main(int argc, char *argv[])
{
   while(scanf("%d",&n)!=EOF)
   {if(n==0)
    break;
                  if(n==1)
                 {cout<<n<<endl;continue;}
                 memset(data,0,sizeof(data));
                
                 dfs(1);
                
   }
                 

   
   



system("PAUSE");
return EXIT_SUCCESS;
}

  评论这张
 
阅读(748)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018