Problem A: 深入淺出學算法002-n個1


Description

由n個1組成的整數能被K(K<10000)整除,n至少為多少?

Input

多組測試數據,第一行輸入整數T,表示組數 然后是T行,每行輸入1個整數代表K

Output

對於每組測試數據輸出1行,值為n

Sample Input

1
11

Sample Output

2
#include <stdio.h>
#include <stdlib.h>
int main(void)
 {
    int t;
    while(scanf("%d",&t)!=EOF)
    { 
    while(t--)
    {
        int k;
        scanf("%d",&k);
        if(k==1)
        {
            printf("1\n");
            continue;
        }int c=1;
        int temp=1;
        while(temp!=0)
        { 
             temp=temp*10+1;
             temp=temp%k;
             c++; 
         }     
        printf("%d\n",c);
    }
    }
    return 0;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM