根据要求求除数的数 与 互素和算法 (的品质因数和欧拉函数分解)

数论问题求解
本文介绍了一种利用欧拉函数解决特定数论问题的方法。针对给定数值n,求解其约数和与不大于n且与n互质的数之和的差值。文章详细解释了使用筛法构建素数表、分解质因数以及计算欧拉函数的过程。

Description

One day, Qz met an easy problem. But after a 5-hout-long contest in CSU, he became very tired and he wanted to call his girlfriend as soon as possible. As we all know, Qz is a genius in plenty of fields especially in programming. But he did not want to write a program to solve this problem, he just want to call his girlfriend. Now he gave this problem to you, and he want you to solve this problem without programming. Fortunately, YH heard about Qz’s bad behavior, and he thought that not everyone is as clever as Qz. Finally, YH managed to persuade Qz to ask you to write a program to solve this problem. The problem is:
Qz will give you only one number N (1<= N <= 10^9), and he wants to know the answer of A sub B, A and B are as follow:
A is sum of series of numbers X (He only cares about X which is no larger than N) .For each X, that exists an integer k satisfies that k * X = N.
B is sum of series of numbers Y (He only cares about Y which is no larger than N).For each Y satisfies that GCD(Y, N) = 1.
YH whispers to you that GCD(X, Y) means the Greatest Common Divisor of X and Y, and you should not let Qz know that YH has told you the secret.
Qz is so hurry so he had no time to give you the N one by one and he will give you multiple cases.
YH is so kind and he ask Qz that for each input file, the number of N is about 30000.

Input

Qz is so hurry to call his girlfriend so he has no time to explain the Input.

Output

Help Qz to output the answer to problems on each line.

Sample Input

1
2
3
4

Sample Output

0
2
1
3


题意:给出一个数n , 求n的约数和减去不大于n且与n互质的数的和,记为a-b。

当时去现场做想到的仅仅有暴力,但10^9超时无疑。后来听出题人的解说,说用到欧拉函数,当时也不怎么明确。

直到今天看到一个性质:上述的b有一个公式,b=(n*f(n))/2。

f(n)代表n的欧拉函数。(有关证明在数论书中能够找到)。

问题转化为求n的约数和。n的欧拉函数。都须要用到分解质因数。将n分解为n=p1^a1*p2^a2*...*pn^an。

n的约数和记为S(n),S(n)的公式不再赘述。


大致思路已经有了。先构造根号n的素数表。由于质因数不会超过根号n,然后就是分解质因数的过程。

该题目能够作为求约束和与不大于n且与n互质的和的模板。

#include<stdio.h>
#include<math.h>
typedef unsigned long long LL;
#define maxn 200000
LL primet[maxn];
int pnum = 0;
LL n,a,b,res;
bool flag[maxn];
void getprimtable()//筛法求出素数
{
    for (long i = 2; i < maxn; i++)
        if (!flag[i]) {
            primet[pnum++] = i;
            for (long j = i + i; j < maxn; j += i) flag[j] = true;
        }
}
LL FF(LL x ,LL y) {
    LL ret=1;
    while(y--) ret*=x;
    return ret;
}
LL eularpk(LL p, int k)//欧拉求p^k
{
    if (k == 0) return 1;
    LL ans = p - 1;
    while (--k) ans *= p;
    return ans;
}
LL f(LL n)//求f 因式分解
{
    LL sum = 1;
    res=1;
    int p, k;
    for (int i = 0; primet[i]*primet[i]<= n; i++) {
        p = primet[i];
        if (n % p == 0) {
            k = 0;
            while (n % p == 0) {n /= p; k++;}
            sum = sum * eularpk(p, k);  // p^k
            res*=( ( FF(p,k+1) -1 ) / (p-1));
        }
    }
    if (n > 1) {      // 分解到最后剩下一个素因子 , 须特别注意。
        sum = sum * eularpk(n, 1); 
        res*=( ( FF(n,2) -1 ) / (n-1));
    }
    return sum;
}
int main() {
    getprimtable();
    while(~scanf("%lld",&n)) {
        LL b=n*f(n)/2;
        if(n == 1) printf("0\n");
        else printf("%lld\n",res-b);
    }
    return 0;
}




一、据采集层:多源人脸据获取 该层负责从不同设备 / 渠道采集人脸原始据,为后续模型训练识别提供基础样本,核心功能包括: 1. 多设备适配采集 实时摄像头采集: 调用计算机内置摄像头(或外接 USB 摄像头),通过OpenCV的VideoCapture接口实时捕获视频流,支持手动触发 “拍照”(按指定快捷键如Space)或自动定时采集(如每 2 秒采集 1 张),采集时自动框选人脸区域(通过Haar级联分类器初步定位),确保样本聚焦人脸。 支持采集参配置:可设置采集分辨率(如 640×480、1280×720)、图像格式(JPG/PNG)、单用户采集量(如默认采集 20 张,确保样本多样性),采集过程中实时显示 “已采集量 / 目标量”,避免样本不足。 本地图像 / 视频导入: 支持批量导入本地人脸图像文件(支持 JPG、PNG、BMP 格式),自动过滤非图像文件;导入视频文件(MP4、AVI 格式)时,可按 “固定帧间隔”(如每 10 帧提取 1 张图像)或 “手动选择帧” 提取人脸样本,适用于无实时摄像头场景。 据集对接: 支持接入公开人脸据集(如 LFW、ORL),通过预设脚本自动读取据集目录结构(按 “用户 ID - 样本图像” 分类),快速构建训练样本库,无需手动采集,降低系统开发测试成本。 2. 采集过程辅助功能 人脸有效性校验:采集时通过OpenCV的Haar级联分类器(或MTCNN轻量级模型)实时检测图像中是否包含人脸,若未检测到人脸(如遮挡、侧脸角度过大),则弹窗提示 “未识别到人脸,请调整姿态”,避免无效样本存入。 样本标签管理:采集时需为每个样本绑定 “用户标签”(如姓名、ID 号),支持手动输入标签或从 Excel 名单批量导入标签(按 “标签 - 采集量” 对应),采集完成后自动按 “标签 - 序号” 命名文件(如 “张三
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值