Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

大水题一个,并不多说,贴代码供参考

Posted by 201501060326 at 2016-02-23 19:56:14 on Problem 3100
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator