Lucky Sum of Digits

A. Lucky Sum of Digits
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 477444 are lucky and 517467 are not.

Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task.

Input

The single line contains an integer n (1 ≤ n ≤ 106) — the sum of digits of the required lucky number.

Output

Print on the single line the result — the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1.

Sample test(s)

input

11

output

47

input

10

output

-1

题意:让你找全部由4,或7,或者4,7组成后的数,每位的和为n的最小的数。
方法:假设全部由4组成,则用4的个数最大为n/4个,假设全部由7组成,则用7最大的个数为n/7个,则用4的范围在0~n/4,用7的范围在0~n/7,然后枚举符合的数,找到4的个数还有7的个数,则最小的数就是4全部在前,7全部在后,输出来就行。
#include
#include
#include
using namespace std;
int n,i,j,k,flag,sum;
int main()
{
	int s4,s7;
	cin>>n;
	s4=n/4; s7=n/7;
	for(i=0;i<=s4;i++)
	{
		for(j=0;j<=s7;j++)
		{
			if(i*4+j*7==n)
			{
				flag=1;
				break;
			}
		}
		if(flag)  break;
	}
	if(!flag)
		cout<<-1<

你可能感兴趣的:(数学题)