阿里巴巴公開賽 HDU 3959 Board Game Dice(數學)

來源:互聯網
上載者:User

 題意有點繞,想了很久 , 還是求教金思密達才明白了題意 , 才出的這個題。

題目就是要找一個比N大的M^x,得到M^x*x/N的最簡分數 , 根據範例,分子是1時不用處理,直接除去gcd就好

沒估出範圍,還是改成long long交的 , 後來試一下 int WA了。

#include <cstdio>typedef long long typen;typen gcd (typen a , typen b){    return b?gcd(b,a%b):a;}typen n,m;int main (){    int cas;    scanf("%d",&cas);    for (int I=1 ; I<=cas ; ++I)    {        scanf("%I64d%I64d",&n,&m);        typen x=1;        typen tmp=m;        for ( ; tmp<n ; ++x,tmp*=m);        //printf("x=%d\n",x);        typen p,q;        p=tmp*x;q=n;        typen d=gcd (p,q);        printf("Case %d: %I64d/%I64d\n",I,p/d,q/d);    }    return 0;}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.