UVA 993 Product of digits (decomposition factor)

Source: Internet
Author: User

UVA 993 Product of digits



Topic: Given a number n, requires a number, so that the number of each bit will be equal to N, and the value of the number is the smallest.

Problem solving: A simple decomposition factor. Note that there are two points: 1) factor from 9 to 2 times, can guarantee the minimum number of bits, 2) when n equals 1 is the best special treatment.



#include <stdio.h> #include <string.h> #include <stdlib.h> #include <algorithm>using namespace Std;int N, dig[100000];int main () {int t;scanf ("%d", &t), while (t--) {scanf ("%d", &n); int flag = 0, cnt = 9, Cnt2 = 0;if (n = = 1) {printf ("1\n"); continue;} while (n! = 1) {if (cnt = = 2 && n% cnt! = 0) {flag = 0;break;} if (n cnt! = 0) {cnt--;} else {flag = 1;n/= cnt;dig[cnt2++] = cnt;cnt = 9;}} if (!flag) printf (" -1\n"), else {for (int i = cnt2-1; I >= 0; i--) {printf ("%d", Dig[i]);} printf ("\ n");}} return 0;}


UVA 993 Product of digits (decomposition factor)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.