容斥二题(HDU4135&4059)

手把手教你配置SAP PP供应区域(Supply Area):实现线边仓精准发料与物料流优化 本文详细解析了SAP PP供应区域(Supply Area)的配置方法,帮助企业实现线边仓精准发料与物料流优化。通过三级优先级逻辑和四步配置法,系统可自动识别最优组件来源位置,显著提升生产订单处理效率和库存准确率。文章还提供了典型问题解决方案和性能优化技巧,适用于离散制造和重复制造场景。 阅读详情

容斥二题(HDU4135&4059)

A.Co-prime

Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 32768/32768 K (Java/Others)

Problem Description
Given a number N N , you are asked to count the number of integers between A and B B inclusive which are relatively prime to N.
Two integers are said to be co-prime or relatively prime if they have no common positive divisors other than 1 1 or, equivalently, if their greatest common divisor is 1. The number 1 1 is relatively prime to every integer.

Input
The first line on input contains T(0<T<=100) the number of test cases, each of the next T lines contains three integers A,B,N A , B , N where (1<=A<=B<=1015) ( 1 <= A <= B <= 10 15 ) and (1<=N<=109) ( 1 <= N <= 10 9 ) .

Output
For each test case, print the number of integers between A A and B inclusive which are relatively prime to N N . Follow the output format below.

Sample Input

2
1 10 2
3 15 5

Sample Output

Case #1: 5
Case #2: 10

Hint
In the first test case, the five integers in range [1,10] which are relatively prime to 2 are [1,3,5,7,9] [ 1 , 3 , 5 , 7 , 9 ] .

Solution
应该都能看出是容斥,只要我们可以算出 [1,x] [ 1 , x ] 之间与n互质的数,那 [a,b] [ a , b ] 之间互质的数就是 [1,b]−[1,a−1] [ 1 , b ] − [ 1 , a − 1 ]
要算出 [1,x] [ 1 , x ] 之间与n互质的数,只要考虑每个质因子的是否出现即可以为一个数的质因子不会太多,直接压位暴力即可

Code

#include <cstdio>
#define N 1000000000
#define M 1000000

using namespace std;
typedef long long LL;
LL q[M], p[M], cnt;
bool pr[M];

inline void init() {
    for (LL i = 2; i * i < M; ++i)
        if (!pr[i])
            for (LL j = 2; j * i < M; ++j)
                pr[i * j] = 1;
    for (LL i = 2; i < M; ++i) {
        if (!pr[i]) p[++cnt] = i;
    }
}

LL make(LL x, LL y) {
    LL o = y, now = 0;
    if (x == 0) return 0;
    for (LL i = 1; p[i] * p[i] <= o && i <= cnt; ++i) {
        if (o % p[i] == 0) {
            q[++now] = p[i];
            while (o % p[i] == 0) o /= p[i];
        }
    }
    if (o > 1) q[++now] = o;
    LL ans = 0;
    for (LL i = 1; i < (1LL << now); ++i) {
        LL u = 1, c = 0;
        for (int j = 0; j < now; ++j) {
            if (i & (1LL << j)) u *= q[j + 1], c++;
        }
        if (c & 1) ans += x / u;
        else ans -= x / u;
    }
    return (LL)x - ans;
}

int main() {
    init();
    LL T, a, b, n;
    scanf("%lld", &T);
    for (LL cas = 1; cas <= T; ++cas) {
        scanf("%lld%lld%lld", &a, &b, &n);
        printf("Case #%lld: %lld\n", cas, make(b, n) - make(a - 1, n));
    }
    return 0;
}

B.The Boss on Mars

Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 32768/32768 K (Java/Others)

Problem Description
On Mars, there is a huge company called ACM (A huge Company on Mars), and it’s owned by a younger boss.

Due to no moons around Mars, the employees can only get the salaries per-year. There are n employees in ACM, and it’s time for them to get salaries from their boss. All employees are numbered from 1 1 to n. With the unknown reasons, if the employee’s work number is k k , he can get k4 Mars dollars this year. So the employees working for the ACM are very rich.

Because the number of employees is so large that the boss of ACM must distribute too much money, he wants to fire the people whose work number is co-prime with n n next year. Now the boss wants to know how much he will save after the dismissal.

Input
The first line contains an integer T indicating the number of test cases. (1≤T≤1000) ( 1 ≤ T ≤ 1000 ) Each test case, there is only one integer n n , indicating the number of employees in ACM. (1≤n≤108)

Output
For each test case, output an integer indicating the money the boss can save. Because the answer is so large, please module the answer with 1,000,000,007 1 , 000 , 000 , 007 .

Sample Input

2
4
5

Sample Output

82
354
Hint

Hint
Case1: sum=1+3∗3∗3∗3=82 s u m = 1 + 3 ∗ 3 ∗ 3 ∗ 3 = 82
Case2: sum=1+2∗2∗2∗2+3∗3∗3∗3+4∗4∗4∗4=354 s u m = 1 + 2 ∗ 2 ∗ 2 ∗ 2 + 3 ∗ 3 ∗ 3 ∗ 3 + 4 ∗ 4 ∗ 4 ∗ 4 = 354

Solution
这题和A题其实并没有本质区别,就是多了一个四次方求和
(我发现最近的最近做到的四次方求和的题特别多,一定要好好补一下)
回到正题
本题与题A唯一不同的地方是 a4+(2a)4+(3a)4+...+(na)4 a 4 + ( 2 a ) 4 + ( 3 a ) 4 + . . . + ( n a ) 4
其实也只是普通的转换,变成 (14+24+34+...+n4)∗a4 ( 1 4 + 2 4 + 3 4 + . . . + n 4 ) ∗ a 4
唯一需要注意的地方(也是我Debug了一个多小时的地方,因为基本上每个数据都是对的)!!!
给的模数是 1e9+7 1 e 9 + 7 ,我以前做过一道这样的题戳这里
E题的题解
当时题目给的 m m 只有1e5,乘上30完全不会爆炸,但是 (109+7)∗30 ( 10 9 + 7 ) ∗ 30 也并不会炸long long啊???
然而有两个数一乘就会炸了。。。
所以不要偷懒,还是求个逆元吧: 30 30 关于 109+7 10 9 + 7 的逆元可以直接算出来是 233333335 233333335
真的 233333333...... 233333333......

Code

#include <cstdio>
#define M 20000
#define PSC 1000000007
#define PP 233333335

using namespace std;
typedef long long LL;
LL q[M], p[M], cnt;
bool pr[M];

inline void init() {
    for (LL i = 2; i * i < M; ++i)
        if (!pr[i])
            for (LL j = 2; j * i < M; ++j)
                pr[i * j] = 1;
    for (LL i = 2; i < M; ++i) {
        if (!pr[i]) p[++cnt] = i;
    }
}

LL make(LL n) {
    LL ans = n % PSC * (n + 1) % PSC * (2 * n + 1) % PSC * ((3 * n % PSC * n % PSC + 3 * n - 1) % PSC) % PSC * PP % PSC;
    return ans;
}

int main() {
    init();
    LL T, a, b, n;
    scanf("%lld", &T);
    for (LL cas = 1; cas <= T; ++cas) {
        scanf("%lld", &n);
        LL o = n, now = 0;
        for (LL i = 1; p[i] * p[i] <= o && i <= cnt; ++i) {
            if (o % p[i] == 0) {
                q[++now] = p[i];
                while (o % p[i] == 0) o /= p[i];
            }
        }
        if (o > 1) q[++now] = o;
        LL ans = 0;
        for (LL i = 1; i < (1LL << now); ++i) {
            LL u = 1, c = 0;
            for (LL j = 0; j < now; ++j) {
                if (i & (1LL << j)) u *= q[j + 1], c++;
            }
            if (c & 1) ans = (ans + make(n / u) * u % PSC * u % PSC * u % PSC * u % PSC) % PSC;
            else ans = (ans - make(n / u) * u % PSC * u % PSC * u % PSC * u % PSC) % PSC;
            if (ans < 0) ans += PSC;
        }
        ans = (make(n) - ans) % PSC;
        if (ans < 0) ans += PSC;
        printf("%lld\n", ans);
    }
    return 0;
}
保姆级教程:用Anaconda+PyCharm搞定YOLOv8本地部署(附避坑指南) 本文提供了一份详细的YOLOv8本地部署指南,涵盖Anaconda环境配置、PyCharm集成到模型部署的全过程。特别针对国内开发者需求,整合了镜像加速和常见报错解决方案,帮助快速完成目标检测模型的本地部署与实战应用。 阅读详情

相关推荐

AI人工智能全模态大模型架构:推动智能交通发展的架构设计

本文旨在阐述全模态大模型在智能交通领域的架构设计原理和应用方法。我们将探讨如何利用多模态AI技术解决交通流量预测、事故预警、路线优化等关键问题。文章将从基础概念入手,逐步深入技术细节,最后探讨实际应用和未来发展方向。全模态大模型:能够处理和理解多种数据模态(如图像、文本、语音等)的大型AI模型智能交通系统(ITS):利用先进技术优化交通流量和安全性的综合系统多模态融合:将不同数据源的信息整合处理的技术核心概念回顾全模态大模型是能够处理多种数据类型的强大AI系统。

AGI×大数据,开启智能时代的认知跃迁;解码AGI,赋能数据驱动的智能革命。 837

Co-prime(数论)(容斥原理)

                                         传送门 题意:给你A,B,N三个数,问你在A,B之间(include),有多少个数与N互质。 A、B已经到了1e15了,暴力是绝对不可能的,这辈子都不可能暴力的。 可以举例说明 m=12,n=30. 第一步:求出n的质因子:2,3,5; 第二步:(1,m)中是n的因子的倍数当然就不互质了(2,4,6,8...

这可是一个难过的暑假哇,别白过 2373

飞腾Ubantu22.04.3安装OpenNebula测试

因OpenneBula官方镜像源只有AMD架构的镜像包不存在ARM的镜像包,借此用源码编译进行测试。

坚持就是胜利的博客 1018

Co-prime (容斥定理)

容斥定理 要计算几个集合并集的大小,我们要先将所有单个集合的大小计算出来,然后减去所有两个集合相交的部分,再加回所有三个集合相交的部分,再减去所有四个集合相交的部分,以此类推,一直计算到所有集合相交的部分。 容斥原理:在计数时,必须注意无一重复,无一遗漏。为了使重叠部分不被重复计算,人们研究出一种新的计数方法,这种方法的基本思想是:先不考虑重叠的情况,把包含于某内容中的所有对象的数目先计算...

qq_44177960的博客 721

从零到一:Firefly-RK3399上的Ubuntu镜像构建与GPU加速实战

本文详细介绍了在Firefly-RK3399开发板上从零构建深度优化的Ubuntu系统镜像的全过程,包括交叉编译环境配置、内核定制、GPU加速环境部署(Mesa Panfrost驱动、OpenCL/Vulkan支持)以及深度学习推理优化(TFLite + LinuxNN)。通过实战案例展示了如何充分发挥Mali-T860 GPU的硬件潜力,提升边缘AI应用的性能和能效。

pz8901234的博客 1029

(遇到问题)(已解决)word敲入的公式转化为mathtype

https://www.mathtype.cn/wenti/wordgongshi-zhuanhuan.html 现在越来越多的人在文档中编辑公式的时候会选择MathType来编辑,因为它包含有众多的数学符号和模板,编辑公式时非常方便。但是也有一些人在编辑公式时没有使用MathType公式编辑器,直接使用Word中自带的公式编辑器来编辑的。当我们需要要共享一份文件的时候,这种用自带公式编辑器编辑出来的文件,在我们安装有MathType公式编辑器的电脑里打开时,双击公式没有反应,是无法对它们进行修改的.

计算机视觉 1万+

hdu 4135 Co-prime(容斥原理)

Co-prime Problem Description Given a number N, you are asked to count the number of integers between A and B inclusive which are relatively prime to N. Two integers are said to be co-prim

Darkarts 851

新能源知识库(37)三代储能电芯介绍

2025年储能电芯三代技术演进概述 截至2025年6月,储能电芯已明确划分为三代: 第一代(280Ah):2019-2023年主流,能量密度180Wh/kg,循环寿命8000次,成本降至0.6元/Wh; 第二代(314Ah):2023年起主导,容量超1kWh,能量密度提升20%,循环寿命达15000次,系统成本降低15%; 第三代(500Ah+):2024年量产,能量密度突破440Wh/L(如宁德时代587Ah、阳光电源684Ah),20尺集装箱容量达6-9MWh,零部件成本降30%。 技术路线分化:卷绕派

竹君子之家 7968

Co-prime(容斥原理求互素数个数)(模板)

HUD4135 题意 求a~b之间与n互素的个数 思路 求出 1~b 之间与n互素的个数减去 1~a-1之间与n互素的的个数即为所求。 #include&lt;cstdio&gt; #include&lt;queue&gt; #include&lt;set&gt; #include&lt;cstdlib&gt; #include&lt;string.h&gt; #include&lt;string&gt; #include&lt;iostream&gt; #include&lt;cmath&gt; #inc

QQ2530063577的博客 778

《涨知识啦29》-DBR的工作原理及其在VCSEL中的作用

分布式布拉格(Distributed Bragg Reflection,简称DBR)反射镜是垂直腔面发射激光器(Vertical-Cavity Surface-Emitting Laser,简称VCSEL)的重要组成部分。典型的DBR反射镜是由1/4ni波长厚度的高折射率和低折射率材料交替组成(ni是该层的折射率)。其反射率取决于组成对数、边界条件以及折射率差。 图1 布拉格反射镜的工作原理 DBR反射镜的工作原理如图1所示。根据反射原理,当光从光疏介质n1射向光密介质n2(折射率n2&gt;n1)时,反

simucal的博客 8034

高通Camx功能feature分析之八:高通NCS服务之架构和初始化

本文介绍了高通NCS(NONCameraSensor)服务的架构与初始化流程。NCS服务通过QMI接口访问非相机传感器,为CameraEIS、AEC等算法节点提供陀螺仪、加速度计等传感器数据支持。文章详细解析了NCS服务的分层架构,包括客户端、服务端、QSEE接口实现等组件,并重点分析了初始化过程中获取传感器列表、查询能力等关键步骤。通过camxsetting.xml中的enableNCSService开关控制服务启动,初始化过程涉及QSEE单例创建、传感器能力查询等核心操作。后续文章将继续深入讲解相关技术

940

【精度问题】Prime Time

题目:https://vjudge.net/contest/70017#problem/W 大佬博客:https://blog.csdn.net/iroy33/article/details/83211685 精度上不去就加一个eps,应该是c++默认同步到最高位小数 但是eps不能为1e-16这样的 #include&lt;cstdio&gt; const int maxm = 1e4...

SummerDream 356

Qt Creator配置MSVC编译环境、调试环境

获取和安装:cdb.exe 在 Debugging tools for Windows 中,而现在已经不单独提供下载,只在Windows SDK 或者Windows Driver Kit里面包含 所以需要下载微软的调试工具,最少需要下载 Windows SDK。在windows上开发,一般使用Qt Creator自带mingw编译器,编译和调试都很方便,安装Qt时勾选后,自动配置完毕。但是有时候我们需要使用MSVC的编译器,这个时候我们没法直接使用,需要配置环境才能使用,以下是配置方案。

希望能帮助大家,希望大家多多支持,你们的支持是我前进的动力。 6997

容斥原理练习

A. HDU 4135 求 \([A,B]\) 中有多少个数与 \(N\) 互质。 \(A,B\le 10^{15},N\le 10^9\) 解 \(O(\sqrt n)\) 找出 \(n\) 的所有质因子,然后指数级容斥。可以证明质因子个数不会超过15个。 B. HDU 4059 \(T\le 1000\) 组询问,给定 \(n\) ,求与 \(n\) 互质的数的四次方和。 解 \(O(\sqr...

weixin_30572613的博客 174

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

c语言容斥原理,容斥原理 | 易学教程

容斥原理\(|A_1\cup A_2\cup...\cup A_n|=\sum\limits_{1\le i\le n}|A_i|-\sum\limits_{1\le i二项式反演形式1\(f_i=\sum_{j=k}^n C(i,j)*g_j \Leftrightarrow g_i=\sum_{j=k}^n (-1)^{i-j}*C(i,j)*f_j\)形式2\(f_i=\sum_{j=k}^n...

weixin_39561577的博客 276

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

Co-prime(质因数分解&&容斥原理)

Co-prime 题意: 给你一个区间 [A,B]。 要你求在这个区间内由多少与 n 互质的数。 思路: 可以先求 ans(A-1) 和 ans(B)。(之后两者相减即可)。 求互质再转换一下,就是求 res 有公因子的总数。总数B 减去 有 公因子的 res。剩下的就是互质的。 先把n 质因数分解。对于每个质因数去考虑它们 p1∪p2∪p3∪p4∪p5...∪pnp_1 \cup p_2 \cup p_3 \cup p_4 \cup p_5 ...\cup p_np1​∪p2​∪p3​∪p4​∪p5​

qq_45377553的博客 474

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

Co-prime(容斥定理)

传送门 Problem Description Given a number N, you are asked to count the number of integers between A and B inclusive which are relatively prime to N. Two integers are said to be co-prime or relatively ...

海绵的博客 516

CF660A -- Co-prime Array

Co-prime Array Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description You are given an array of n elements, you must make it a co-prime array in as few

ah_yeah 605

【HDU】4135 - Co-prime(容斥原理)

点击打开题目 Co-prime Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3495    Accepted Submission(s): 1381 Problem Description Giv

wyg1997 1730

Co-prime(容斥定理+数论)

Co-prime Given a number N, you are asked to count the number of integers between A and B inclusive which are relatively prime to N. Two integers are said to be co-prime or relatively prime if they h...

codeswarrior的博客 405

Co-prime

http://acm.hdu.edu.cn/showproblem.php?pid=4135 Co-prime Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2481    Accepted Submission(s):

ACcoders 735

HDU 4135 Co-prime(容斥原理 + 基础数论)

传送门 Co-primeTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3695    Accepted Submission(s): 1461Problem Description Given a number N, you are as

代码改变世界 1837

hdu4135 Co-prime(分解质因数,容斥)

Co-prime Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4433    Accepted Submission(s): 1755 Problem Description Given a number N,

spark__s的博客 1077

G - Co-prime(分解质因子+容斥定理)

https://vjudge.net/contest/280477#problem/G Given a number N, you are asked to count the number of integers between A and B inclusive which are relatively prime to N.  Two integers are said to be co-...

qq_43490894的博客 260

HDU6025 Coprime Sequence【前缀GCD+后缀GCD】

Coprime Sequence Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1415Accepted Submission(s): 690 Problem Description Do yo...

海岛Blog 2569
上一篇: 【模板】线段树
下一篇: CodeForces 379F-New Year Tree(LCA+直径)
北路人
博客等级 码龄9年 21粉丝 62原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值