ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1009. K-based Numbers

WHY MY ALGORITM IS WRONG?
Posted by Gevorg Soghomonyan(YSU) 1 Apr 2009 17:37
#include<iostream.h>

int power(int a, int b)
{
    if(b==0)
        return 1;
    if(b%2==0)
        return power(a, b/2) * power(a, b/2);
    if(b%2!=0)
        return power(a, b/2) * power(a, b/2) * a;
}

int main()
{
    int n, k;
    cin>>n>>k;
    int a, b;
    a=power(k, n-1) * (k-1);
    b=power(2, n-1);
    cout<<a-b+n<<endl;
    return 0;
}
I think that the answer of this problem is
(k-1)*k^(n-1)-2^(n-1)+n why it is wrong i don't understand.
Re: WHY MY ALGORITM IS WRONG?
Posted by bzaz 2 Apr 2009 20:18
Because it is not working!!!!!!!!!!!!!!!!!!!!!
Re: WHY MY ALGORITM IS WRONG?
Posted by Ivan (Vologda SPU) 3 Oct 2009 19:41
yes it doesn't! =)
Re: WHY MY ALGORITM IS WRONG?
Posted by Oleg Strekalovsky aka OSt [Vologda SPU] 4 Oct 2009 01:01
Ivan (Vologda SPU) wrote 3 October 2009 19:41
yes it doesn't! =)
Don't use alien wrong solution!