1 条题解

  • 0
    @ 2025-4-7 21:41:57

    C :

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

    C++ :

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

    Java :

    import java.math.BigInteger;
    import java.util.Scanner;
    
    public class Main
    {
    	public static void main(String args[])
    	{
    		Scanner cin = new Scanner(System.in);
    		while(cin.hasNext()){
    			BigInteger n;
    			n=cin.nextBigInteger();
    			if(n.equals(BigInteger.ONE)){
    				System.out.println(1);
    				continue;
    			}
    			BigInteger tem=BigInteger.valueOf(11);
    			int f=2;
    			while(!tem.mod(n).equals(BigInteger.ZERO)){
    				f++;
    				tem=tem.multiply(BigInteger.valueOf(10)).add(BigInteger.ONE);
    			}
    			System.out.println(f);
    		}
    	}
    }
    
    • 1

    信息

    ID
    2086
    时间
    1000ms
    内存
    32MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者