1727. Znaika's Magic Numbers

原题链接: http://acm.timus.ru/problem.aspx?space=1&num=1727






//使用 C# 语言解答如下:

using System;

// http://acm.timus.ru/problem.aspx?space=1&num=1727
static class Timus
{
  static void Main()
  {
    int n = int.Parse(Console.ReadLine());
    int count = Compute(ref n), tops = count;
    for (int i = 0; n > 9; i++, n -= 10) count++;
    int tens = count - tops;
    Console.WriteLine(count += ((n > 0) ? 1 : 0));
    for (int i = 99999; tops-- > 0; i--) Console.Write(i + " ");
    while (tens-- > 0) Console.Write("19 28 37 46 ".Substring(tens * 3, 3));
    if (n > 0) Console.Write(n);
  }
  
  static int Compute(ref int n)
  {
    int count = 0;
    for (int sum = 45; n >= 45; )
    {
      n -= sum--;
      if (++count % 10 == 0) sum += 9;
      if (count % 100 == 0) sum += 9;
      if (count % 1000 == 0) sum += 9; 
    }
    return count;
  }
}



1727. Znaika's Magic Numbers

Time limit: 0.5 second
Memory limit: 64 MB
Znaika has many interests. For example, now he is investigating the properties of number sets. Znaika writes down some set consisting of different positive integers (he calls this set a  generating set), calculates the sum of all the written digits, and writes down the result in a special notebook. For example, for a generating set 7, 12, 43, he will write down the number  17 = 7 + 1 + 2 + 4 + 3 . Znaika is sure that only  magic numbers can appear as a result of this operation.
Neznaika laughs at Znaika. He thinks that there is a generating set for every number, and he even made a bet with Znaika that he would be able to construct such a set.
Help Neznaika win the bet and construct a generating set for a given number.

Input

The only input line contains an integer  n (0 <  n < 10 5).

Output

If it is possible to construct a generating set for the number  n, output the number of elements in this set in the first line. In the second line output a space-separated list of these elements. The elements of the set must be different positive integers strictly less than 10 5. If there are several generating sets, output any of them. If there are no generating sets, output −1.

Sample

input output
17
3
7 12 43
Problem Author: Ivan Burmistrov
Problem Source: Ural Regional School Programming Contest 2009
Tags: none 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值