Advertisement
MyOnAsSalat

Untitled

Feb 16th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.73 KB | None | 0 0
  1. using System;
  2.  
  3.  
  4. class Program
  5. {
  6.     static void Main()
  7.     {
  8.         int n = Convert.ToInt32(Console.ReadLine());
  9.         if (n == 1)
  10.         {
  11.             Console.WriteLine(9);
  12.             return;
  13.         }
  14.         ulong result = 9;
  15.         for (int i = 2; i <= n; i++)
  16.         {
  17.             if (i % 2 == 0)
  18.             {
  19.                 result +=  9 * (ulong)Math.Pow(10, i/2 - 1);
  20.             }
  21.             else
  22.             {
  23.                result += 90 * (ulong)Math.Pow(10, (i-1)/2-1);
  24.             }
  25.             result = result > 10000007 ? module(result): result;
  26.  
  27.         }
  28.         Console.WriteLine(result);
  29.     }
  30.  
  31.     static ulong module(ulong a)
  32.     {
  33.         return a % ((ulong) Math.Pow(10,9)+7);
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement