hdu 1299 Diophantus of Alexandria

来源:互联网 发布:网络搜索排名 编辑:程序博客网 时间:2024/04/27 19:15

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1299
题目大意:

求方程1/x+1/y=1/n的解的个数

分析:

1/x+1/y = 1/n 设y = n + k;

==>1/x + 1/(n+k)=1/n;

==>x = n^2/k + n;

因为x为整数,k就是n^2的约数。

/*Heal The WorldThere's a place in your heartAnd I know that it is loveAnd this place could be muchBrighter than tomorrowAnd if you really tryYou'll find there's no need to cryIn this place you'll feelThere's no hurt or sorrowThere are ways to get thereIf you care enough for the livingMake a little spaceMake a better placeHeal the worldMake it a better placeFor you and for meAnd the entire human raceThere are people dyingIf you care enough for the livingMake it a better placeFor you and for meIf you want to know whyThere's love that cannot lieLove is strongIt only cares of joyful givingIf we try we shall seeIn this bliss we cannot feelFear od dreadWe stop existing and start livingThe it feels that alwaysLove's enough for us growingSo make a better worldMake a better placeHeal the worldMake it a better placeFor you and for meAnd the entire human raceThere are people dyingIf you care enough for the livingMake a better place for you and for meAnd the dream we were conceived inWill reveal a joyful faceAnd the world we once believed inWill shine again in graceThen why do we keep strangling lifeWound this earth' crucify its soulThough it's plain to seeThis world is heavenlyBe god's glowWe could fly so highLet our spirits never dieIn my heart I feel you are all my brothersCreate a world with no fearTogether we cry happy tearsSee the nations turntheir swords into plowsharesWe could really get thereIf you cared enough for the livingMake a little spaceTo make a better placeHeal the worldMake it a better placeFor you and for meAnd the entire human raceThere are people dyingIf you care neough for the livingMake a better place for you and for meHeal the worldMake it a better placeFor you and for meAnd the entire human raceThere are people dyingIf you care neough for the livingMake a better place for you and for meHeal the worldMake it a better placeFor you and for meAnd the entire human raceThere are people dyingIf you care neough for the livingMake a better place for you and for meThere are pepole dyingIf you care enough for the living*/#include <iostream>#include <cstring>#include <cstdio>using namespace std;const int maxn=1e7+5;typedef long long LL;bool prime[maxn];int p[maxn/10];//素数int k;//一共有多少个素数int num[1000];//素因子的个数,注意这里不要开的太大,容易超内存int cnt;//多少个素因子void isprime()//素数筛{    k=0;    LL i,j;//注意long long     memset(prime, true, sizeof(prime));    for(LL i=2; i<maxn; i++)    {        if(prime[i])        {            p[k]=i;            k++;            for(j=i*i; j<maxn; j+=i)            prime[j]=false;        }    }}LL fenjie(LL n)//素因子分解{    cnt=0;    LL ans=1;    memset(num, 0, sizeof(num));    for(int i=0; p[i]*p[i]<=n&&i<k; i++)    {        if(n % p[i] == 0)        {            //fac[cnt]=p[i];            while(n%p[i]==0)            {                num[cnt]++;                n/=p[i];            }            cnt++;        }    }    if(n>1)    {        //fac[cnt]=n;        num[cnt++]=1;    }    for(int i=0;i<cnt;i++)//n*n的个数        ans*=(2*num[i]+1);    return ans;}int main(){    isprime();    int m,cas=1;    scanf("%d",&m);    while(m--)    {        LL x;        scanf("%lld",&x);        printf("Scenario #%d:\n%lld\n\n",cas++,(fenjie(x)+1)/2);    }    return 0;}
0 0
原创粉丝点击