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 1012. K-based Numbers. Version 2

why wa in test 1?
Posted by bottles 20 Oct 2007 06:33
#include<iostream>
#include<cstdio>
using namespace std;

int solve(int n,int k){
    unsigned long long a[3]={0};

    a[0]=1;
    a[1]=k-1;
    for(int i=2;i<=n;i++)
        a[i%3]=(k-1)*(a[(i-1)%3]+a[(i-2)%3]);

    printf("%I64u\n",a[n]);
    return 0;
}

int main()
{
    int n,k;
    //while(1){
    scanf("%d%d",&n,&k);
    solve(n,k);
//}
    return 0;
}