HDU 6134 Battlestation Operational-莫比乌斯

一生一芯——用RTL实现最简单的处理器NPC(南大数逻计组RV32ICPU) 代码及思考参考 本文介绍自己前期用Verilog编写的基于RV32I指令集的CPU,个人认为是最简单最易懂的版本(即没做什么优化,即代码很水,没有考虑一些奇怪的情况,只适用简单指令序列,即题目所示最简单的处理器),适合新手练手Verilog以及了解简单CPU的运行过程。本文基于一生一芯,利用Verilator进行仿真,并用gtkwave查看波形,不了解verilator和gtkwave的可以看前几篇文章。 阅读详情

 

Battlestation Operational

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 653    Accepted Submission(s): 367


Problem Description
> The Death Star, known officially as the DS-1 Orbital Battle Station, also known as the Death Star I, the First Death Star, Project Stardust internally, and simply the Ultimate Weapon in early development stages, was a moon-sized, deep-space mobile battle station constructed by the Galactic Empire. Designed to fire a single planet-destroying superlaser powered by massive kyber crystals, it was the pet project of the Emperor, Darth Vader, and its eventual commander Grand Moff Wilhuff Tarkin to expound the military philosophy of the aptly named Tarkin Doctrine.
>
> — Wookieepedia

In the story of the Rogue One, the rebels risked their lives stolen the construction plan of the Death Star before it can cause catastrophic damage to the rebel base. According to the documents, the main weapon of the Death Star, the Superlaser, emits asymmetric energy in the battlefield that cause photons to annihilate and burns everything in a single shot.

You are assigned the task to estimate the damage of one shot of the Superlaser.

Assuming that the battlefield is an n×n grid. The energy field ignited by the Superlaser is asymmetric over the grid. For the cell at i-th row and j-th column, ⌈i/j⌉ units of damage will be caused. Furthermore, due to the quantum effects, the energies in a cell cancel out if gcd(i,j)≠1 or i<j.

The figure below illustrates the damage caused to each cell for
n=100. A cell in black indicates that this cell will not be damaged due to the quantum effects. Otherwise, different colors denote different units of damages.

Your should calculate the total damage to the battlefield. Formally, you should compute
f(n)=∑i=1n∑j=1i⌈ij⌉[(i,j)=1],


where [(i,j)=1] evaluates to be 1 if gcd(i,j)=1, otherwise 0.
 

Input
There are multiple test cases.

Each line of the input, there is an integer n (1≤n≤106), as described in the problem.

There are up to
104 test cases.
 

Output
For each test case, output one integer in one line denoting the total damage of the Superlaser, f(n) mod 109+7.
 

Sample Input
1 2 3 10
 

Sample Output
1 3 8 110



/*
题意 : 要你计算题目中的公式,那个公式简单点来说就是给出一个n,
计算出  i 从 1 到 n,j 从1 到 i ,当 i 与 j互质的时候 答案计数加上[i/j](向上取整)

题解:
做俩个函数 F[i] (表示 i / 1 + i / 2 + ... + i / i 向上取整)
f[i] (表示 i / 1 + i / 2 + ... + i / i 向下取整)
可以发现规律是

1)F[i] = f[i - 1] + i 因为前一项向下取整 后一项的向上取整就是所对应的每个数的值都加1 所以就是加i 
例如
5/1 = 5     4/1 = 4      1
5/2 = 3     4/2 = 2      1
5/3 = 2     4/3 = 1      1
5/4 = 2     4/4 = 1      1
5/5 = 1           0      1

2)f[i] = F[i] - i +(i的因子数)对于当前得F[i]来说 每一项都是向上取整得 要求他向下取整得数,
那么就要减去那些不能整除i的数,那些数是通过向上取整取得的,所以要减去,
直接找那些数不好找 但是找i的因子容易,那么就直接先把F[i]减去i,然后再加上i的因子个数
例如
4/1 = 4   4/1 = 4   0
4/2 = 2   4/2 = 2   0
4/3 = 1   4/3 = 2   1
4/4 = 1   4/4 = 1   0    f[4] = F[4] - 4 + 3

3)这样就算完了F[i],但是里面还有要除去的,就是那些不互质的数也被计算到里面去了,要刨去这一部分
比如2,它只有在 i = 2 的时候 2 / 1 可以计数加2,在 i = 4 的时候 i / 2 = 2 计数也加2了,但是4与2是不互质的
所以要刨去,因为这里的容斥条件是互质关系,所以这部分的容斥可以用到莫比乌斯容斥。
例如:F[12]
12/1  = 12          6/1 = 6
12/2  = 6 *         6/2 = 3
12/3  = 4           6/3 = 2
12/4  = 3 *         6/4 = 2
12/5  = 3           6/5 = 2
12/6  = 2 *         6/6 = 1
12/7  = 2
12/8  = 2 *
12/9  = 2
12/10 = 2 *
12/11 = 2
12/12 = 1 *
*/

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <iostream>
using namespace std;
typedef long long ll;
const int maxn = 1e6+10;
const int INF = 0x3f3f3f;
const int mod  = 1e9+7;
int mub[maxn],prim[maxn];
bool visit[maxn];
int F[maxn],f[maxn];

void mobius(){
    mub[1] = 1;
    for(int i = 2;i<maxn;++i){
        if(!visit[i]){
            mub[i] = -1;
            prim[++prim[0]] = i;
        }
        for(int j = 1;j<=prim[0] && i*prim[j] < maxn;++j){
            visit[i*prim[j]] = 1;
            if(i%prim[j]==0){///i是primes[j]的整数倍时,i*primes[j]就会包含相同质因子,例如6和3=18
                mub[i*prim[j]] = 0;
                break;
            }
            else///i与prim[j]互质,利用其积性函数的特性得
                mub[i*prim[j]] = -mub[i];///mub[k]=mub[i]*mub[primes[j]] 而primes[j]是质数 mub值为-1
        }
    }
}

void init(){
    F[1] = f[1] = 1;
    for(int i = 2;i<maxn;++i){
        F[i] = f[i-1]+i;
        int x = i;
        int ans = 1;///i的因子个数
        for(int j = 1;prim[j]*prim[j]<=i;++j){
            int cnt = 1;
            while(x%prim[j]==0){
                cnt++;
                x/=prim[j];
            }
            ans *= cnt;
        }
        if(x>1) ans*= 2;/// i可能为素数 则有1和它本身两个因子
        f[i] = F[i]-i+ans;/// 向下取整的等于向上取整的刨去一层然后加上因子个数(是因子的才有贡献)
    }

    for(int i = 2;i<maxn;++i){///f[i]已经没用了
        f[i] = F[i];
    }
    for(int i = 2;i<maxn;++i){
        for(int j = i;j<maxn;j+=i){///j要能除开i
            if(mub[i]){
                F[j]+=mub[i] *f[j/i];///mub[i]可能是正数可能是负数,达到了减多了再加回来目的
            }
        }
    }
    for(int i =2;i<maxn;++i){
        F[i] += F[i-1];
        F[i] %= mod;
    }

}

int main(){
    mobius();
    init();
    int n;
    while(scanf("%d",&n)!=EOF){
        printf("%d\n",F[n]);
    }
    return 0;
}



先楫HPM6E00EVK EtherCAT从站配置与CIA402 8轴运动控制实战解析 本文详细解析了先楫HPM6E00EVK开发板的EtherCAT从站配置与CIA402 8轴运动控制实战。从环境准备、XML文件配置、代码移植到TwinCAT工程设置,提供了完整的移植指南,帮助开发者实现高效的多轴同步运动控制。 阅读详情

相关推荐

001-基础入门-Web演示源码&资源&工具箱等

小迪安全2023笔记

wushangyu32335的博客 4293

HDU 6134 Battlestation Operational(基本数论+莫比乌斯反演)——2017 Multi-University Training Contest - Team 8

传送门Battlestation OperationalTime Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 570    Accepted Submission(s): 317Problem Description > The Death Sta

代码改变世界 938

超实用!用 Ollama + DeepSeek + Dify 搭建本地知识库,提升企业效率

本文介绍了如何使用 Ollama + DeepSeek + Dify 搭建本地知识库,帮助企业高效管理信息。通过简单配置,可实现智能问答、文档检索等功能,提升效率并保障数据安全。

Happiness is everywhere 4305

2017多校八 1002题 hdu 6134 Battlestation Operational 艾弗森约定 莫比乌斯函数 分块

题目链接 题意: Your should calculate the total damage to the battlefield. Formally, you should compute f(n)=∑i=1n∑j=1i⌈ij⌉[(i,j)=1], where [(i,j)=1] evaluates to be 1 if gcd(i,j)=1,

kkkkahlua的博客 832

AI Agent ReAct架构设计模型剖析

ReAct通过"思考-行动-观察"循环运作:智能体先进行自然语言推理,再调用外部工具执行行动,观察结果后继续推理直至解决问题。这种架构提高了透明度和准确性,减少幻觉风险,使LLM能主动分解任务并利用外部数据源。实现关键在于精心设计的提示模板,引导LLM按结构化格式响应,而非依赖模型固有能力。

weixin_43939320的博客 1259

n8n智能体开发:Microsoft Outlook 节点

使用 Microsoft Outlook 节点可以自动化 Microsoft Outlook 工作流程,并将其与其他应用程序集成。n8n 内置支持多种 Microsoft Outlook 功能,包括创建、更新、删除和获取文件夹、邮件及草稿等操作。

王国平的博客 572

HDU6134 Battlestation Operational 【莫比乌斯】

链接设g(n)=∑ni=1∑ij=1ceiling(ij)设g(n)=\sum_{i=1}^n\sum_{j=1}^{i}ceiling(\frac{i}{j}) g(n/3)=∑n/3i=1∑ij=1ceiling(ij)=∑n/3i=1∑ij=1ceiling(3i3j)g(n/3)=\sum_{i=1}^{n/3}\sum_{j=1}^{i}ceiling(\frac{i}{j})=\sum

LuRiCheng的博客 434

一套适合 ABAP 初级和中级开发人员,从入门到提高的 ABAP 学习教程

曾几何时,ABAP 就是 SAP 的代名词。ABAP 这门编程语言造就了 SAP 名噪一时的 R/3 产品,同时也是如今 SAP 旗舰级产品,SAP S/4HANA 底层的实现语言。 ABAP 不仅代表着 SAP 这家公司在企业级管理软件市场辉煌的过去,ABAP 自身也在不断地进化着。SAP 不仅在本地部署(On-Premise)领域继续保持着自己绝对的统治地位,而且在云应用领域(Software-as-a-Service, 简称 SaaS), 也推出了自己的解决方案,比如 SAP S/4HANA Clo

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 5994

HDU 6134 Battlestation Operational 莫比乌斯反演 + 数学推导

传送门:HDU 6134 题意:给定n,求: 思路: 以上转自:点击打开链接 上面的推导过程中最重要也是最不好理解的就是‘重要发现’那里,我们可以举个例子解释,假设n = 12 那么等式右边就为(12/1 + 12/2 + 12/ 3 + 12/ 4 + 12/5 + 12/6 + 12/7 + 12/8 + 12/9 + 12/10 + 12/11 + 12/12) 然后

WA是一笔财富 571

【声纳技术】声呐时间反转镜技术:从被动聚焦到主动空间复用

时间反转镜技术以其独特的物理机制,为水声通信与声呐探测提供了一条绕过传统自适应均衡器的新路径。被动时间反转利用接收端的空间分集实现脉冲压缩,结构简洁、计算高效;主动时间反转则通过发射端预编码,将多径能量引导至目标位置,为多用户下行链路的空间复用奠定了物理基础。从Kuperman等人在海洋中首次验证声学时间反转镜,到TR-MIMO声呐的湖试验证,再到VTRM-CRK多用户通信系统的海试成功,该技术已从理论概念逐步走向工程实用。

u012133341的博客 62

《拉依达的嵌入式\驱动面试宝典》—Linux篇(八)_Linux驱动编程

《拉依达的嵌入式\驱动面试宝典》 整合了所有我认为可能遇到的技术面试问题。所有问题及其答案均是我个人学习后查阅资料总结,每个回答都做了仔细的分析,在嵌入式及其驱动面试相关问题解析做到全网独一无二。学习或者转行到嵌入式、驱动开发领域学习的不二之选

拉依达不拉跨的博客 324

【HDU6134】Battlestation Operational (莫比乌斯反演)

多校第八场没想到碰到了一直想学却没有学的莫比乌斯反演,比赛时不出意外的打出了gg,便下定决心要好好会一会高深的莫比乌斯反演(在菜鸡的眼里是这样),下面是我的一些学习资料: http://www.cnblogs.com/chenyang920/p/4811995.html http://blog.csdn.net/acdreamers/article/details/8542292 https...

receiling的博客 647

【Java面试题汇总】JVM篇(2026版)

JVM内存模型、双亲委派模型、类加载机制、内存溢出、垃圾回收机制、内存泄漏、垃圾回收流程、垃圾回收器、G1、CMS、JVM调优

种一棵树最好的时间是十年前,其次是现在 3万+

【HDU6134】Battlestation Operational(莫比乌斯反演)

2017 Multi-University Training Contest - Team 8题目链接题目大意: 让你求f(n)=∑i=1n∑j=1n⌈ij⌉[(i,j)=1]f(n) = \sum_{i = 1}^{n} \sum_{j = 1}^{n} \lceil \frac{i}{j} \rceil [(i, j) = 1]理解了q巨的解法后,对反演理解了点。。以下

No Program No Life 718

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

HDU 6134 Battlestation Operational(莫比乌斯反演)

HDU 6134 Battlestation Operational(莫比乌斯反演) 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6134 题目大意:给定正整数 nnn ,求 ∑i=1n∑j=1i⌈ij⌉[gcd⁡(i,j)=1](1≤n≤1e6)\sum\limits_{i=1}^n\sum\limits_{j=1}^i\lceil\frac{i}{j}\rceil[\gcd(i,j)=1](1\leq n\leq 1e6)i=1∑n​j=1∑i​⌈ji​

m0_52639539的博客 206

jre9下载 jdk9

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

Battlestation Operational(hdu6134 莫比乌斯反演)

题目:点击打开链接 题意:f(n) = sigma[1 sigma代表求和符号,celi代表除完向上取整; 解题:个人觉得这个代码还挺容易看懂的 点击打开链接 #include using namespace std; typedef long long ll; const ll mod=1e9+7; const ll maxn=1e6+5; int mu[maxn],prime

xiaohang3414的博客 360

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

hdu6134 Battlestation Operational 莫比乌斯反演

题目: ,(i,j)==1表示gcd(i,j)=1。 思路: 令F[i]=i/1+i/2+...+i/i 向上取整 D[i]=i/1+i/2+...+i/i 向下取整 其中F[i]=D[i-1]+1,D[i]=F[i]-i+cnt,cnt为i的因子的个数 然后就可以使用容斥定理了。 代码: #pragma comment(linker, "/STACK:1024000000

ACVevtor的博客 403

hdu 6134 Battlestation Operational 莫比乌斯反演

题目链接点这里 #include using namespace std; #define INF 0x3f3f3f3f #define INFLL 0x3f3f3f3f3f3f3f3f #define FIN freopen("in.txt","r",stdin); #define mem(x,y) memset(x,y,sizeof(x)); typedef

我们做的队 820

HDU 6134 Battlestation Operational 2017多校8 莫比乌斯反演

#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include //#include using namespace std; #def

lych4o的博客 259

hdu 6134 Battlestation Operational (莫比乌斯反演+反演一般做法)

题目链接:哆啦A梦传送门 题意: 求f(n)=∑i=1n∑j=1i⌈ni⌉[gcd(i,j)==1]f(n)=\sum_{i=1}^{n}\sum_{j=1}^{i}\lceil \frac{n}{i} \rceil [gcd(i,j)==1]f(n)=∑i=1n​∑j=1i​⌈in​⌉[gcd(i,j)==1] 题解:参考博客:神犇 此公式大部分都是参考博客里面的。 我们先化简一下: f(n)=...

Jiandong 388

【HDU】6134 Battlestation Operational-莫比乌斯反演

莫比乌斯反演+调和级数

远行客 316

2017多校第8场 HDU 6134 Battlestation Operational 莫比乌斯反演

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6134 题意: 解法: 那么g(n)怎么求,我们尝试打表发现g(n)是有规律的,g(n)=g(n-1)+d(n-1)+1,其中d(i)表示i的因子个数,这个我们是可以通过线性筛O(n)处理出来的,之后再O(n)维护g(i)的前缀和,就可以在单组sqrt(n)的复杂度下得到答案了。...

aishangg437965的博客 175

HDU 6134 Battlestation Operational(莫比乌斯反演+线性筛)

Battlestation Operational Input There are multiple test cases. Each line of the input, there is an integer n (1≤n≤106), as described in the problem. There are up to 104 test cases.  Output

Expecto__Patronum的博客 503

hdu 6134 Battlestation Operational (莫比乌斯反演+埃式筛)

Problem Description > The Death Star, known officially as the DS-1 Orbital Battle Station, also known as the Death Star I, the First Death Star, Project Stardust internally, and simply the...

dddddd12345456的博客 202

【数论】【莫比乌斯反演】【线性筛】hdu6134 Battlestation Operational

看这个题解吧:http://blog.csdn.net/wubaizhe/article/details/77338332 代码里顺便把几个常用的线性筛附上了。 Key:1、gcd(i,j)==1利用莫比乌斯函数的性质进行转化。 2、变换求和符号的顺序。 3、发现,该式可以递推。 4、线性筛约数个数函数。 #include<cstdio> #include<...

weixin_33937499的博客 106

hdu 6134 Battlestation Operational (莫比乌斯反演+线性筛法+差分)

http://acm.hdu.edu.cn/showproblem.php?pid=6134 题目大意:给你一个n,求f(n)=∑ni=1∑ij=1⌈ij⌉其中gcd(i,j)=1f(n)=\sum_{i=1}^{n}\sum_{j=1}^{i}\left \lceil \frac{i}{j} \right \rceil其中 gcd\left ( i,j \right ) = 1。解题思路:根据已

Merry_hj的博客 938
上一篇: hdu 6124 Smallest Minimum Cut - 最少边最小割-2017 ICPC网络赛青岛站 -1009
下一篇: L. The Heaviest Non-decreasing Subsequence Problem -最长不降子序列变形nlogn-2017 ACM-ICPC 亚洲区(南宁赛区)网络赛
lyyy.
博客等级 码龄11年 170粉丝 236原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值