Участник/Novruzov.sb/Encode Integer — различия между версиями

Материал из DISCOPAL
Перейти к: навигация, поиск
(Новая страница: «https://www.spoj.com/problems/SNGINT/ c++ <code-cpp> #include <bits/stdc++.h> int main(void) { unsigned int cases_cnt; if (!(scanf("%u", &cases_cnt))) {…»)
 
Строка 1: Строка 1:
 
https://www.spoj.com/problems/SNGINT/
 
https://www.spoj.com/problems/SNGINT/
  
c++
+
С++
 
<code-cpp>
 
<code-cpp>
 
#include <bits/stdc++.h>
 
#include <bits/stdc++.h>

Версия 19:27, 27 ноября 2020

https://www.spoj.com/problems/SNGINT/

С++

#include <bits/stdc++.h>
 
int main(void) {
 
  unsigned int cases_cnt;
 
  if (!(scanf("%u", &cases_cnt))) {
    return -1;
  }
  std::vector<unsigned int> div;
 
  unsigned int in;
  while (cases_cnt--) {
    scanf("%u", &in);
 
    bool pos = true;
    if (in == 0) {
      printf("10\n");
      pos = false;
    }
    if (in == 1) {
      printf("1\n");
      pos = false;
    }
 
    div.clear();
    while (in != 1 && (pos)) {
      unsigned int temp = in;
      for (unsigned int i = 9; i > 1; i--) {
        while ((in % i) == 0) {
 
          in /= i;
          div.push_back(i);
        }
      }
      if (temp == in) {
        printf("-1\n");
        pos = false;
      }
    }
 
    if (pos) {
      sort(div.begin(), div.end());
 
      for (unsigned int i = 0; i < div.size(); i++) {
 
        printf("%u", div.at(i));
      }
      putchar('\n');
    }
  }
 
  return 0;
}