Блог пользователя aleksey.pechenin

Автор aleksey.pechenin, 12 лет назад, По-английски

Hello Guys. I've solved problem above in the title, but I very fill bad yourself on my solutions.

code:

static void Main(string[] args) { long k = long.Parse(Console.ReadLine());

long l = long.Parse(Console.ReadLine());

        long stepen = (long)Math.Round(Math.Log(l, k) - 0.4);

        long result = k;

        for (int i = 0; i < stepen - 1; i++)
        {
            result = result * k;
        }

        if (result == l)
        {
            Console.WriteLine("YES");
            Console.WriteLine(stepen - 1);
        }
        else
        {
            Console.WriteLine("NO");
        }
    }

I suppose, there is another good approach how I can determine accuracy of degree. One of the unpleasant things that when we compute Math.log(1000000000,10) then result is 8.9~

Any suggestions will be very appreciated.

Полный текст и комментарии »

  • Проголосовать: нравится
  • -9
  • Проголосовать: не нравится

Автор aleksey.pechenin, 12 лет назад, По-русски

Hello guys, I've tried to solve problem 131B, but I got WA on 10 test.

the problem is appeared so easy, but probably I've made mistake in my calculations.

What's wrong here?

static void Main(string[] args)
    {

       Console.ReadLine();
       string[] s = Console.ReadLine().Split(' ');
       Dictionary<long,long> a = new Dictionary<long,long>();
       for (int i = 0; i<s.Length;i++){
          long key = long.Parse(s[i]);
          if (!a.ContainsKey(key)) {
             a[key] = 0;
          }
          a[key] ++;
       }

       long count = 0;
       foreach (long item in a.Keys) {
         if (item == 0) {
          count = count + (a[item]*(a[item]-1)/2); 
          continue;
         }
         if (item>0) {
           if (a.ContainsKey(-item)) {
              count = a[item] * a[-item];
           }
         }
       }
       Console.WriteLine(count);
    }        
}

}

Полный текст и комментарии »

  • Проголосовать: нравится
  • -7
  • Проголосовать: не нравится