所以代表N的因數一定都落於2~9之間
一旦從9除到2(有重複因數,可以重複除), 最後得到結果不為1代表沒有存在的Q
中間有除到的因數 組起來就是答案(先除的放到後面)
基本上只有一位數的解答就是自身
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <iterator> | |
#include <algorithm> | |
#include <string> | |
using namespace std; | |
int main(){ | |
for( | |
std::istream_iterator<int> iiter(std::cin), eof; | |
++iiter != eof;){ | |
int n = *iiter; | |
if( n < 10 ){ | |
cout << n << endl; | |
} | |
else { | |
std::string result; | |
for(int i = 10 ; --i > 1 ; ) | |
for( ; | |
n % i == 0 ; | |
n /= i, | |
result = ::to_string(i) + result | |
); | |
cout << (n ^ 1 ? -1 : ::stoi(result)) << endl; | |
} | |
} | |
} |
0 意見:
張貼留言
Click to see the code!
To insert emoticon you must added at least one space before the code.