|
|
вернуться в форум#include<iostream.h> #include<stdio.h> int main() { int n,i,k;unsigned __int64 a[2000],p; cin>>n>>k;a[1]=k-1;a[2]=k*(k-1); for(i=3;i<=n;i++) {a[i]=(k-1)*(a[i-1]+a[i-2]);p=a[i];} if(n==1) cout<<k-1; else if(n==2) cout<<k*(k-1); else if(n>=3) printf("%I64u", p); return 0; } You should use long arithmetic!!! CAN I SOLVE IT WHITOUT LONG ARITHMETIC?THANK!!! 1)hacking ;) - bad way 2)find answers for all test cases but more easy to write LA Edited by author 11.04.2007 18:10 I have the solution!!! do you want |
|
|