Advertisement
golergka

spoj.pl Factorial

May 29th, 2012
218
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. namespace Factorial
  4. {
  5.     class MainClass
  6.     {
  7.        
  8.         static int z (int x)
  9.         {
  10.             int result = 0;
  11.             int[] fivePowerModulo = new int[ (int)Math.Log (x, 5) + 1];
  12.             for (int i=1; i<=x; i++) {
  13.                
  14.                 int j = 0;
  15.                
  16.                 Power:
  17.                 fivePowerModulo [j]++;
  18.                 if (fivePowerModulo [j] == 5) {
  19.                     fivePowerModulo [j] = 0;
  20.                     j++;
  21.                     goto Power;
  22.                 }
  23.                
  24.                 result += j;
  25.                
  26.             }
  27.             return result;
  28.         }
  29.        
  30.         public static void Main (string[] args)
  31.         {
  32.             int testCases = Convert.ToInt32 (Console.ReadLine ());
  33.             int[] xs = new int[testCases];
  34.             for (int i=0; i<testCases; i++)
  35.                 xs [i] = Convert.ToInt32 (Console.ReadLine ());
  36.             foreach (int x in xs)
  37.                 Console.WriteLine (z (x));
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement