Codeforces B. Nearest fraction running result is inconsistent with codeblocks running result. Please advise

Source: Internet
Author: User

Http://codeforces.com/problemset/problem/281/ B

My code for this question is:

#include<cstdio>#include<cmath>using namespace std;long long int gcd(long int a,long int b){    return a==0?b:gcd(b%a,a);}int main(){    long long int x,y,n,mina,minb;    while(scanf("%I64d%I64d%I64d",&x,&y,&n)!=EOF)    {        int temp=gcd(x,y);        x/=temp;        y/=temp;        if(n>=y)        {            printf("%I64d/%I64d\n",x,y);            continue;        }        for(int i=1; i<=n; i++)        {            int a1=x*i/y;            int a2=a1+1;            if(i==1)            {                mina=a1;                minb=i;            }            if(fabs(a1*1.0/i-x*1.0/y)<fabs(mina*1.0/minb-x*1.0/y))            {                mina=a1;                minb=i;            }            if(fabs(a2*1.0/i-x*1.0/y)<fabs(mina*1.0/minb-x*1.0/y))            {                mina=a2;                minb=i;            }        }        temp=gcd(mina,minb);        printf("%I64d/%I64d\n",mina/temp,minb/temp);    }    return 0;}

I use the codeblocks compiler and input 1/1 and output. However, after submitting the code on CF, the output is as follows:

How should I change the program?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.