HDU 1299 Diophantus of Alexandria

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

题意:求满足\frac{1}{x}+\frac{1}{y}= \frac{1}{n}这个关系的所有x,y的对数。

思路:首先x,y必定大于n,然后令y=n+k可以推出x= \frac{n^2}{k}+n,因为x是正整数,所以k一定是n*n的约数,再有约数个数定理可以知道对于一个大于1正整数n可以分解质因数:,则n的正约数的个数就是。我们每次求出n的素因子的个数然后*2就是n*n的素因子的个数了。

#pragma comment(linker, "/STACK:102400000,102400000")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define MOD 1e9+7
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define DBN1(a)           cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)         cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)       cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)     cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e)   cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN6(a,b,c,d,e,f) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<", "<<#f<<"="<<(f)<<"\n"
using namespace std;
typedef long long ll;
const int maxn=100000+5;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
template<typename T>
inline T read(T&x){
    x=0;int _f=0;char ch=getchar();
    while(ch<'0'||ch>'9')_f|=(ch=='-'),ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x=_f?-x:x;
}
int prime[maxn],n,T,ans;
bool isprime[maxn];
void init(){
    for (int i=2;i*i<=1000000000;i++){
        if (!isprime[i]) prime[++prime[0]]=i;
        for (int j=1;j<=prime[0] && i*prime[j]<=100000;j++){
            isprime[i*prime[j]]=true;
            if (i%prime[j]==0) break;
        }
    }
}
int main(){
    init();
    int cas=1;
    for (read(T);T;T--){
        read(n);
        ans=1;
        int N=n;
        for (int i=1;i<=prime[0] && prime[i]*prime[i]<=N;i++){
            int cnt=0;
            while (n%prime[i]==0) cnt++,n/=prime[i];
            ans*=(1+cnt*2);
        }
        if (n>1) ans*=3;//剩下来的是质数
        printf("Scenario #%d:\n",cas++);
        printf("%d\n\n",(ans+1)/2);
    }
    return 0;
}

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注