Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
大水题一个,并不多说,贴代码供参考#include <stdio.h> int find(int x,int y) { if(x==0) return 0; else if(y==0) return 1; else return x*find(x,y-1); } int abx(int x) { return x<0?-x:x; } int main() { int b,n,a,i,d,ds,dt; while(scanf("%d%d",&b,&n),b!=0&&n!=0) { for(i=1;; i++) { ds=abx(b-find(i,n)); if(i==1) { d=ds; dt=i; } else if(d>ds) { d=ds; dt=i; } else { printf("%d\n",dt); break; } } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator