Skip to content

Instantly share code, notes, and snippets.

@staticor
Created July 16, 2013 03:13
Show Gist options
  • Save staticor/6005474 to your computer and use it in GitHub Desktop.
Save staticor/6005474 to your computer and use it in GitHub Desktop.
using System;
using System.Linq;
using System.Collections.Generic;
 
// http://acm.timus.ru/problem.aspx?space=1&num=1727
static class Timus
{
  static void Main()
  {
    var n = int.Parse(Console.ReadLine());
    var set = Compute(ref n);
    var count = set.Count;
    for (var i = 0; n > 9; i++, n -= 10) count++;
    var tens = count - set.Count;
    Console.WriteLine(count += ((n > 0) ? 1 : 0));
    foreach (var i in set) Console.Write(i + " ");
    while (tens-- > 0) Console.Write("19 28 37 46 ".Substring(tens * 3, 3));
    if (n > 0) Console.Write(n);
    Console.WriteLine();
  }
   
  static HashSet<int> Compute(ref int n)
  {
    var set = new HashSet<int>();
    for (var rand = new Random(); n >= 45; )
    {
      var k = rand.Next(100, 100000);
      if (set.Add(k)) n -= k.ToString().Select(x => x - '0').Sum();
    }
    return set;
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment