poj1426
Find The Multiple
| Time Limit: 1000MS | Memory Limit: 10000K | |||
| Total Submissions: 10685 | Accepted: 4404 | 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
沒有仔細分析題目,我一看最后的output不會超過100位,我就在想怎么存呢
想了好久也沒想出好方法,如果數組存的話,可能會超內存,判斷也可能會超時,最后現不到好辦法
我還想要不要用double存,然后只是判斷麻煩一些而以,
結果去網上找題解發現,只要longlong就能出正解
呃……我是沙茶
還有隊列開了好大,要定義成全局變量
1#include<stdio.h>
2#include<string.h>
3#include<math.h>
4int n;
5long long now,q[1000000];
6void bfs()
7{
8int head,tail;
9head=0;
10tail=1;
11q[tail]=1;
12while(head<tail)
13{
14head++;
15now=q[head];
16now=now*10;
17if(now%n==0)
18{
19break;
20}
21tail++;
22q[tail]=now;
23tail++;
24q[tail]=now+1;
25}
26printf("%I64d\n",now);
27}
28int main()
29{
30while(scanf("%d",&n)!=EOF&&n!=0)
31{
32bfs();
33}
34return 0;
35}
36





}
}

