☀L1-046 Divide the bachelor (20 points)[PTA][Number Theory][Analog Division]

The so-called "bachelor" here does not mean a single person. It refers to a number consisting of all 1, such as 1, 11, 111, 1111, etc. Legend has it that any bachelor can be divisible by an odd number that does not end in 5. For example, 111111 can be divisible by 13. Now, your program needs to read an integer x. This integer must be odd and not ending in 5. Then, after calculation, output two numbers: the first number sindicates that the xmultiplier sis a bachelor, and the second number nis the number of digits of the bachelor. Such a solution is of course not unique. The problem requires you to output the smallest solution.

Tip: An obvious way is to gradually increase the number of bachelors until they can be divided evenly x. But the difficulty is that it smay be a very large number-for example, if the program enters 31, then 3582259390681 and 15 are output, because the result of multiplying 31 by 358429390681 is 111111111111111, a total of 15 ones.

Input format:

Enter a positive odd number x(<1000) that does not end in 5 in one line .

Output format:

Corresponding minimum output in a row sand n, separated by a space therebetween.

Input sample:

31

Sample output:

3584229390681 15

ac code:

//  main.cpp
//  猫猫头
//
//  Created by Mintink on 2020/1/12.
//  Copyright © 2020 Mintink. All rights reserved.
//

#include<iostream>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<vector>
#include<queue>
#include<array>
#include <stdlib.h>
#include <stdio.h>
#include<cstdio>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
//tuple<int,string,int>p[55];
//pair<int,string>male[55],female[55];
priority_queue<ll,vector<ll>,greater<ll> >qa;//升序,大根堆
priority_queue<ll>qd;//降序,小根堆
//const int mod=10e9+7;
typedef long long  ll;
//vector<int>v;
/*
//Max common factor
ll gcd(ll a,ll b)
{
    ll m;
    m=a%b;
    while(m!=0)
    {
        a=b;
        b=m;
        m=a%b;
    }
    return b;
}*/
int main()
{
    int x;
    cin>>x;
    int n=1;
    ll s=1;
    while(s<x)
    {
        s=s*10+1;
        n++;
    }
    while(1)
    {
        cout<<s/x;
        if(s%x==0)
            break;
        s=(s%x)*10+1;
        n++;
    }
    cout<<" "<<n<<endl;
    return 0;
}

 

Guess you like

Origin blog.csdn.net/qq_43660826/article/details/108475921