Decomposition time limit for the number:MS | Memory limit:65535 KB Difficulty:1
-
Describe
-
Your task is to find a minimum positive integer q so that the product of the Q's number of members equals N.
-
Input
-
Up to 450 sets of test data. The data ends with EOF.
Enter an integer N (0≤n≤400).
-
Output
-
Output Q, if Q does not exist then output −1.
-
Sample input
-
105
-
Sample output
-
255
-
Source
-
Ural
1#include <stdio.h>2#include <iostream>3 4 using namespacestd;5 6 intMain () {7 intN;8 while(SCANF ("%d", &n)! =EOF) {9 Ten inti =0, Ge,shi,bai,qi; One for(; I <=10000&& n;i++){ A if(I <Ten){ - if(i = =N) - Break; the } - Else if(I < -){ -GE = i%Ten; -Shi = I/Ten; + if(GE * Shi = =N) - Break; + } A Else if(I < +){ atGE = i%Ten; -Shi = (I/Ten)%Ten; -Bai = I/ -; - if(GE * shi * bai = =N) - Break; - } in Else { -GE = i%Ten; toShi = (I/Ten)%Ten; +Bai = (I/ -)%Ten; -Qi = I/ +; the if(GE * shi * bai * qi==N) * Break; $ }Panax Notoginseng } - if(i==10001) thecout<<-1<<Endl; + Else if(n==0) Acout<<Ten<<Endl; the Else +cout<<i<<Endl; - } $ $ return 0; -}
View Code
1#include <cstdio>2#include <cstring>3#include <string>4#include <iostream>5#include <algorithm>6 using namespacestd;7 intres[Ten];8 9 intMain ()Ten { One intN; A while(SCANF ("%d", &n)! =EOF) - { -memset (Res,0,sizeof(res)); the if(n = =0) -{printf ("10\n");Continue;}//Easy Error - Else if(N <Ten) -{printf ("%d\n", n);Continue;} + Else - { + intTMP =N; A for(inti =9; I >=2; )//number of factors in statistics 2-9 (reverse is key ~) at { - if(tmp% i = =0) - { -res[i]++; -TMP/=i; - } in Else -i--; to } + if(tmp >Ten) {printf ("-1\n");Continue;} - for(inti =2; I <=9; ++i)//from small to large output each factor can be the for(intj =1; J <= Res[i]; ++j) *printf"%d", i); $printf"\ n");Panax Notoginseng } - } the return 0; +}
View Code
The second method is more common
If a number N (0<=n<=1000000000), then the second method should be used
Decomposition time limit for numbers: Ms | Memory limit: 65535 KB Difficulty: 1