Product of Digits URAL - 1014

2023-11-09 16:20
文章标签 ural digits product 1014

本文主要是介绍Product of Digits URAL - 1014,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Your task is to find the minimal positive integer number Q so that the product of digits of Q is exactly equal to N.
Input
The input contains the single integer number N (0 ≤ N ≤ 10 9).
Output
Your program should print to the output the only number Q. If such a number does not exist print −1.
Example
inputoutput
10
25

题意

求最小正整数的乘积是n

思路

简单题,注意0时输出10即可

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[20];
ll flag;
ll w;
void f(ll x)
{ll i;if(x==1){flag=1;return ;}for(i=9;i>=2;i--){if(x%i==0){a[i]++;f(x/i);return ;}}
}
int main()
{ll n,i;flag=0;cin>>n;w=0;if(n==0){printf("10\n");return 0;}if(n==1){printf("1\n");return 0;}memset(a,0,sizeof(a));f(n);
//    for(i=2;i<=9;i++)
//        printf("%d ",a[i]);if(!flag) printf("-1\n");else{for(i=2;i<=9;i++){while(a[i]){printf("%lld",i);a[i]--;}}printf("\n");}return 0;
}

这篇关于Product of Digits URAL - 1014的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/377212

相关文章

uva 10061 How many zero's and how many digits ?(不同进制阶乘末尾几个0)+poj 1401

题意是求在base进制下的 n!的结果有几位数,末尾有几个0。 想起刚开始的时候做的一道10进制下的n阶乘末尾有几个零,以及之前有做过的一道n阶乘的位数。 当时都是在10进制下的。 10进制下的做法是: 1. n阶位数:直接 lg(n!)就是得数的位数。 2. n阶末尾0的个数:由于2 * 5 将会在得数中以0的形式存在,所以计算2或者计算5,由于因子中出现5必然出现2,所以直接一

ural 1297. Palindrome dp

1297. Palindrome Time limit: 1.0 second Memory limit: 64 MB The “U.S. Robots” HQ has just received a rather alarming anonymous letter. It states that the agent from the competing «Robots Unli

ural 1149. Sinus Dances dfs

1149. Sinus Dances Time limit: 1.0 second Memory limit: 64 MB Let  An = sin(1–sin(2+sin(3–sin(4+…sin( n))…) Let  Sn = (…( A 1+ n) A 2+ n–1) A 3+…+2) An+1 For given  N print  SN Input One

ural 1820. Ural Steaks 贪心

1820. Ural Steaks Time limit: 0.5 second Memory limit: 64 MB After the personal contest, happy but hungry programmers dropped into the restaurant “Ural Steaks” and ordered  n specialty steaks

ural 1017. Staircases DP

1017. Staircases Time limit: 1.0 second Memory limit: 64 MB One curious child has a set of  N little bricks (5 ≤  N ≤ 500). From these bricks he builds different staircases. Staircase consist

ural 1026. Questions and Answers 查询

1026. Questions and Answers Time limit: 2.0 second Memory limit: 64 MB Background The database of the Pentagon contains a top-secret information. We don’t know what the information is — you

ural 1014. Product of Digits贪心

1014. Product of Digits Time limit: 1.0 second Memory limit: 64 MB Your task is to find the minimal positive integer number  Q so that the product of digits of  Q is exactly equal to  N. Inpu

leetcode#628. Maximum Product of Three Numbers

题目 Given an integer array, find three numbers whose product is maximum and output the maximum product. Example 1: Input: [1,2,3]Output: 6 Example 2: Input: [1,2,3,4]Output: 24 Note: The lengt

如何将Product依赖的LibraryModule导出成jar

在Android Studio新建Module时可以选择创建的module是工程module还是Android Library。 或者可以在工程module中的build.gradle文件中将 apply plugin: 'com.android.application'改为apply plugin: 'com.android.library' 同时将applicati

[LeetCode] 238. Product of Array Except Self

题:https://leetcode.com/problems/product-of-array-except-self/description/ 题目 Given an array nums of n integers where n > 1, return an array output such that output[i] is equal to the product of all