F-等式

链接:https://www.nowcoder.com/acm/contest/90/F
来源:牛客网

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32768K,其他语言65536K
64bit IO Format: %lld
题目描述
给定n,求1/x + 1/y = 1/n (x<=y)的解数。(x、y、n均为正整数)

输入描述:
在第一行输入一个正整数T。
接下来有T行,每行输入一个正整数n,请求出符合该方程要求的解数。
(1<=n<=1e9)
输出描述:
输出符合该方程要求的解数。
示例1
输入
3
1
20180101
1000000000
输出
1
5
181
1/x + 1/y = 1/n –> xn +yn = xy –> n^2 + xn + yn - xy = n^2 –> (n-x)(n-y) = n^2 事实上是(x-n)(y-n) = n^2,因为y >= x >= n。
于是求n^2的因子即可,考虑n的质数分解n = p1^a1 * p2^a2…pk^ak,n的因子数=(a1 + 1)..(ak + 1),n^2 = p1^2a1 * p2^2a2 … pk^2ak,n^2 的因子数=(2a1 + 1)…(2ak +1).

#include <iostream>
#include <string>
#include <set>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <queue>
#include <cstring>
#include <stack>
#include <vector>
#include <map>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
int main() {
    int T, n;
    cin >> T;
    while (T--) {
        cin >> n;
        int t = sqrt(n);
        ll sum = 1;
        for (int i = 2; i <= t; ++i) {
            int a = 0;
            while ((n % i) == 0) {
                //cout << i << endl;
                n /= i;
                a++;
            }
            sum = sum * (2*a + 1);
        }
        if (n > 1) {
            sum *= 3;
        }
        printf("%lld\n", (sum + 1) / 2);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值