POJ 1426-Find The Multiple【搜索】

悠悠 2022-08-20 14:14 264阅读 0赞

Find The Multiple
















Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 24187   Accepted: 10015   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

  1. 2
  2. 6
  3. 19
  4. 0

Sample Output

  1. 10
  2. 100100100100100100
  3. 111111111111111111

解题思路:

long long 是可以过得。

  1. #include<stdio.h>
  2. #include<queue>
  3. using namespace std;
  4. int n;
  5. void bfs(int d)
  6. {
  7. queue<long long>q;
  8. q.push(d);
  9. while(!q.empty())
  10. {
  11. long long xx=q.front();
  12. q.pop();
  13. if(xx%n==0)
  14. {
  15. printf("%lld\n",xx);
  16. return;
  17. }
  18. q.push(xx*10);
  19. q.push(xx*10+1);
  20. }
  21. }
  22. int main()
  23. {
  24. while(scanf("%d",&n)!=EOF)
  25. {
  26. if(n==0)
  27. break;
  28. bfs(1);
  29. }
  30. return 0;
  31. }

发表评论

表情:
评论列表 (有 0 条评论,264人围观)

还没有评论,来说两句吧...

相关阅读