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

1012 My Code Help
Posted by daiwb 18 Jun 2003 09:20
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

long c(double n,double m){
    long i;
    double result=1;
    for(i=(long)m+1;i<=(long)n;i++){
        result*=(double)i/(double)(i-m);
    }
    return (long)result;
}

int main(void){
    long num_zero,i;
    double k,n,sum=0;
    cin>>n>>k;
    num_zero=(long)n/2;
    for(i=0;i<=num_zero;i++){
        sum+=pow(k-1,n-i)*c(n-i,i);
    }
    cout<<setiosflags(ios::fixed)<<setprecision(0)<<sum<<endl;
    return 0;
}