第13届景驰-埃森哲杯广东工业大学ACM程序设计大赛 F-等式 简单数论题

传送门:点击打开链接


分析:运用质数唯一分解定理求解

首先等式可以变化为 n(x+y) = xy 也就是 n^2 = (n-x)(n-y)

对n^2质数分解也就是对n质数分解


具体实现见代码:

#include <cstdio>
#include <cstring>
using namespace std;

const int maxn = 70;
int a[maxn],tot;
int ans,n;

int main(){
    int T;
    scanf("%d",&T);
    while (T--) {
        scanf("%d",&n);
        tot = 0;
        memset(a,0,sizeof(a));
        for (int i=2; i*i<=n; i++) if (n%i==0) {
            while (n%i==0) a[tot]++, n/=i;
            tot++;
        }
        if (n>1) a[tot++]++;

        for (int i=0; i<tot; i++) a[i]<<=1; //左移相当于乘2,因为前面是对n分解,实际是要对n^2分解
        ans = 1;
        for (int i=0; i<tot; i++) ans *= (a[i]+1); // 加1是吧零次幂情况考虑进去
        printf("%d\n",(ans+1)/2); // 除以2是因为题目要求x<=y
    }
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值