poj 1289 The Cat in the Hat

来源:互联网 发布:mac 计时钟表 编辑:程序博客网 时间:2024/04/30 11:11

大水题一道。

#include<cstdio>#include<cstring>#include<iostream>using namespace std;int main(void){    int a,b;    while(1)    {     scanf("%d %d",&a,&b);     if(a==0&&b==0)        break;      int t1,t2,n = 0;     bool flag = true;     while(flag)     {         ++n;         t1 = t2 = 1;         while(t1<a)         {          t1 *= (n+1);          t2 *= n;         }        if(t1==a&&t2==b)        {         flag = false;          break;        }      }      int ans1, ans2 = 0;      if(n==1)      {          ans1 = 0;      }      else      {          ans1 = (b-1)/(n-1) ;      }      int tmp1,tmp2 = b;      tmp1 = 1;      for(;;)      {       ans2 += tmp1*tmp2;       if(tmp2==1)          break;       tmp1 *= n+1;       tmp2 /= n;      }      cout<<ans1<<" "<<ans2<<endl;    }    return 0;}


原创粉丝点击