等式(试除法与算术基本定理)

  • 题面
  • 题意:见题面。
  • 解决思路: 观察题意,用 x \small x 表示 y \small y
    y = n x x n   ( x n n x ) \small \therefore y=\frac{nx}{x-n}{~(x-n\mid nx)}
    此时,会发现这个式子不好计算,所以考虑用一个参数 t \small t x , y , n \small x,y,n 联系起来。
    t = x n \small t=x-n y = n ( n + t ) t   ( t n 2 + n t ) \small y=\frac{n(n+t)}{t}~(t\mid n^2+nt)
    y = n + n 2 t   ( t n 2 ) \small \therefore y=n+\frac{n^2}{t}~(t\mid n^2) x = n + t \small x=n+t
    y \small y 的个数就是 n 2 \small n^2 的因子的个数,通过对 n 2 \small n^2 求因子个数肯定超时,所以考虑唯一分解。
    n = p 1 q 1 p 2 q 2 . . . p n q n \small n=p_1^{q_1}p_2^{q_2}...p_n^{q_n} n 2 = ( p 1 q 1 p 2 q 2 . . . p n q n ) 2 \small n^2=(p_1^{q_1}p_2^{q_2}...p_n^{q_n})^2
    n 2 \small n^2 的因子个数等于 ( 2 q 1 + 1 ) ( 2 q 2 + 1 ) . . . ( 2 q n + 1 ) \small (2q_1+1)(2q_2+1)...(2q_n+1) q 1 , q 2 . . . q n \small q_1,q_2...q_n 可通过对 n \small n 用试除法算出, n 2 \small n^2 的因子个数就可得到。
    x y \small \because x\leq y
    n + t n + n 2 t \small \therefore n+t\leq n+\frac{n^2}{t}     ~\small \rightarrow~ t n \small\small t\leq n
    所以答案就是 n 2 \small n^2中 小于等于 n \small n 的因子个数就是 n 2 \small n^2 的因子个数对 2 \small 2 上取整 ( \small( n 2 \small n^2 的因子个数为奇数 ) \small )
  • AC代码
//优化
#pragma GCC optimize(2)
//C
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
//C++
//#include<unordered_map>
#include<algorithm>
#include<iostream>
#include<istream>
#include<iomanip>
#include<climits>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
//宏定义
#define N 2010
#define DoIdo main
//#define scanf scanf_s
#define it set<ll>::iterator
//定义+命名空间
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 998244353;
const ll INF = 1e18;
const int maxn = 5e6 + 10;
using namespace std;
//全局变量
const double pi = acos(-1);
//函数区
ll max(ll a, ll b) { return a > b ? a : b; }
ll min(ll a, ll b) { return a < b ? a : b; }
//主函数
int DoIdo() {
 
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
 
    int T;
    cin >> T;
 
    while (T--) {
        int n;
        cin >> n;
 
        int ans = 1;
        for (int i = 2; i * i <= n; i++) {
            if (n % i == 0) {
                int cnt = 0;
                while (n % i == 0) { n /= i; cnt++; }
                ans *= (cnt * 2 + 1);
            }
        }
        if (n >= 2) ans *= 3;
        cout << ans / 2 + 1 << endl;
    }
    return 0;
}
//分割线---------------------------------QWQ
/*
 
 
*/

猜你喜欢

转载自blog.csdn.net/qq_45739057/article/details/106209025