hdu 1299 Diophantus of Alexandria

简介:

题目链接: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 World
There's a place in your heart
And I know that it is love
And this place could be much
Brighter than tomorrow
And if you really try
You'll find there's no need to cry
In this place you'll feel
There's no hurt or sorrow
There are ways to get there
If you care enough for the living
Make a little space
Make a better place
Heal the world
Make it a better place
For you and for me
And the entire human race
There are people dying
If you care enough for the living
Make it a better place
For you and for me
If you want to know why
There's love that cannot lie
Love is strong
It only cares of joyful giving
If we try we shall see
In this bliss we cannot feel
Fear od dread
We stop existing and start living
The it feels that always
Love's enough for us growing
So make a better world
Make a better place
Heal the world
Make it a better place
For you and for me
And the entire human race
There are people dying
If you care enough for the living
Make a better place for you and for me
And the dream we were conceived in
Will reveal a joyful face
And the world we once believed in
Will shine again in grace
Then why do we keep strangling life
Wound this earth' crucify its soul
Though it's plain to see
This world is heavenly
Be god's glow
We could fly so high
Let our spirits never die
In my heart I feel you are all my brothers
Create a world with no fear
Together we cry happy tears
See the nations turn
their swords into plowshares
We could really get there
If you cared enough for the living
Make a little space
To make a better place
Heal the world
Make it a better place
For you and for me
And the entire human race
There are people dying
If you care neough for the living
Make a better place for you and for me
Heal the world
Make it a better place
For you and for me
And the entire human race
There are people dying
If you care neough for the living
Make a better place for you and for me
Heal the world
Make it a better place
For you and for me
And the entire human race
There are people dying
If you care neough for the living
Make a better place for you and for me
There are pepole dying
If 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;
}
目录
相关文章
|
6月前
|
Java
HDU-4552-怪盗基德的挑战书
HDU-4552-怪盗基德的挑战书
39 0
|
Java 测试技术
hdu 1228 A + B
hdu 1228 A + B
47 0
hdu 1856 More is better
点击hdu 1856思路: 思路: 离散化+并查集 分析: 1 点数最多为10^7,但是边数最多10^5,所以我们必须采用离散化,然后利用带权并查集的思想,rank[x]表示的是以x为根节点的集合的元素个数 2 这一题主要注意的就是当...
828 0
|
Java
HDU 1846(巴什博弈)
Brave Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4050    Accepted Submission(s): 2644 Problem Description 十年前读大学的时候,中国每年都要从国外引进一些电影大片,其中有一部电影就叫《勇敢者的游戏》(英文名称:Zathura),一直到现在,我依然对于电影中的部分电脑特技印象深刻。
791 0
|
人工智能 Java
HDU 1257
最少拦截系统 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4182    Accepted Submission(s): 1528 ...
782 0