http://codeforces.com/problemset/problem/281/B
这个题我的代码是:
#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; }
我用的是codeblocks编译器,输入7 6 3 输出1/1,但是CF上提交后显示如下:
应该怎么改程序呢?