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

JAVA
Posted by Imran Yusubov 12 Apr 2009 14:34
import java.util.Scanner;

public class Kb_numb {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
       int i,n,k;
       int[] F=new int[20];
       Scanner in=new Scanner(System.in);
       n=in.nextInt();
       k=in.nextInt();
       F[0]=k-1;
       F[1]=k*F[0];
       for(i=2;i<n;i++){
            F[i]=(F[i-1]+F[i-2])*(k-1);
       }
       System.out.print(F[n-1]);
    }

}