Degree of Bear and digital [common factor] ---- Baidu Star 2019 · Programming Contest - Preliminary Round two: 1001

Degree of Bear and digital

Accepts: 3638 Submissions: 7683
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Problem Description

Of Bear found that 11, 33 and 99 the three figures is amazing, each digit of all of their multiples and must be a multiple of their own. Said example: 5454 is a multiple of 33, while a multiple of 5 + 4 = 95 + 4 = 9 is 33. In another example, 666666 is a multiple of 99, while the 6 + 6 + 6 + 6 = 186 multiples of 18 + 6 = 99 is.
Bear degree also found, in addition to 11, 33, 99 other than a positive integer, although not satisfied, "each digit of all the multiples and must be a multiple of their own", but there are some multiple of the number of their digital and you and also their multiples. For example say, 888888 is a multiple of 1212, and the digits and his 8 + 8 + 8 + 8 + 8 = 248 = 24 is a multiple of 1212.
Now of Bear I want to know, to give you a positive integer VV, the existence of a number of xx, xx so that VV is a multiple of each digit and it also xx and multiples of it? Please identify all such number xx.

Input

"Interrogation plurality of sets, the first line contains a positive integer T on behalf of several groups of interrogation, then data row for each test, comprising a positive integer V .

  • 1≤T≤100
  • 1≤V≤109

Output

For each query, the output of two lines, the first line contains a positive integer m , m representatives for the interrogation of V , there are several conditions satisfying X . The second line of the output m number, satisfying all the conditions of x small to large outputs.

Sample Input

3
1
9
666666

Sample Output

1
1
. 3
1. 3. 9
. 6
1 2. 6. 9. 3 18 is
Note
the first query, the 11 Members of the number and 1 = 1 × 1 , itself equal to 1 × 1 are a multiple of, and therefore a indeed V = 1 s answer.
A third interrogation, 666666 each digit and of 36 × = 9. 4 , itself equal to 9 × 7474 are 9 fold, so 9 indeed V = 666666 answers, after careful calculation can be found, in addition to 9 except that 1,2,3,6,18 are also answers.

Subject to the effect that seek to make Vthe V的各位和public factor, Vthe range is available 10e9 V各位和maximum of not more than 100 violent solution as follows.

Code:

//1001
#include<iostream> 
#include<vector>
using namespace std;

int main(){
    ios::sync_with_stdio(false) ;
    int t,v,tv,sum;
    vector<int> vec(100);
    cin>>t;
    while(t--){
        cin>>tv; v = tv;sum = 0; vec.clear();
        while(tv){
            sum += tv %10;
            tv /= 10;
        }
        for(int i = 1 ; i <= sum;i++ ){
            if(v % i == 0 && sum % i == 0)vec.push_back(i);
        }
        cout << vec.size()<<endl;
        for(int i = 0;i < vec.size();i++){
            cout<< vec[i];
            if(i == vec.size()-1) cout << endl;
            else cout << " ";
        }
    }

    return 0;
}

Guess you like

Origin www.cnblogs.com/zhangxiaomao/p/11374144.html