UVA107等比数列注意特判

来源:互联网 发布:关闭数据还用流量 编辑:程序博客网 时间:2024/04/29 19:14

这题WA了一上午,最后找特判,想了好久竟然没有想到sc=1的特判情况,也是醉了,加了个特判分分钟AC了

#include<cstdio>#include<iostream>#include<vector>#include<queue>#include<algorithm>#include<string>#include<cstdlib>#include<map>#include<set>#include<cmath>#include<cstring>#include<cctype>#include<climits>#include<memory>#include<climits>using namespace std;#define LL long long#define INT (1<<31)-1const int maxn=1000;const double eps=1e-12;int dcmp(double x){    if(fabs(x)<eps)        return 0;    else        return x>0?1:-1;}int main(){    int h,sc;    while(cin>>h>>sc)    {        if(h==0&&sc==0) break;        int nw=0,sh=0;        int i,x;        if(sc==1)        {            nw=log(h)/log(2);            sh=2*h-1;        }        else        {            for(i=1;i<10000;i++)            {                if(h%(i+1)==0&&sc%i==0&&dcmp(log10(h)/log10(1+i)-log10(sc)/log10(i))==0)                {                    break;                }            }            nw=(sc-1)/(i-1);            sh=h*(i+1)-sc*i;        }        cout<<nw<<' '<<sh<<endl;    }    return 0;}


0 0
原创粉丝点击