[CF542D]Superhero's Job

题目大意:

定义函数

\[J(x) = \sum_{\substack{1 \leq k \leq x \\ k \mid x \\ \gcd \left( k, x / k \right) = 1}} k
\]

给定\(n(n\le10^{12})\),求方程\(J(x)=n\)的解的个数。

思路:

对于\(\gcd(a,b)=1\),\(J(ab)=J(a)J(b)\)。

对于\(p\in\mathbb{P}\),\(J(p^k)=p^k+1\)。

\(10^{12}\)内,约数最多的数\(\tau(963761198400)=6720\)。

DP:\(f[i]\)表示组成第\(i\)种有用的约数的方案数。

源代码:

#include<map>
#include<cstdio>
#include<cctype>
#include<vector>
#include<algorithm>
typedef long long int64;
inline int64 getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int64 x=ch^'0';
while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
return x;
}
const int D=6721;
std::vector<int64> p;
std::map<int64,int> map;
int64 d[D],f[D];
int main() {
const int64 n=getint();
for(register int64 i=1;i*i<=n;i++) {
if(n%i) continue;
d[++d[0]]=i;
if(i*i!=n) d[++d[0]]=n/i;
}
std::sort(&d[1],&d[d[0]]+1);
for(register int i=1;i<=d[0];i++) {
map[d[i]]=i;
int64 x=d[i]-1;
for(register int64 j=2;j*j<=x;j++) {
if(x%j) continue;
while(x%j==0) x/=j;
if(x==1) p.push_back(j);
}
if(x>1) p.push_back(x);
}
std::sort(p.begin(),p.end());
p.resize(std::unique(p.begin(),p.end())-p.begin());
const int m=p.size();
f[1]=1;
for(register int i=0;i<m;i++) {
for(register int j=d[0];j;j--) {
int64 t=p[i];
while(t<d[j]) {
if(d[j]%(t+1)==0) {
f[j]+=f[map[d[j]/(t+1)]];
}
t*=p[i];
}
}
}
printf("%lld\n",f[d[0]]);
return 0;
}

[CF542D]Superhero's Job的更多相关文章

  1. 【CF542D】Superhero's Job 暴力

    [CF542D]Superhero's Job 题意:$ f(x)=\sum\limits_{d|x,gcd(d,{x\over d})=1} d$ 给出 $A$ ,求方程 $f(x)=A$ 的正整数 ...

  2. E. Superhero Battle Codeforces Round #547 (Div. 3) 思维题

    E. Superhero Battle time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. Codeforces 542D Superhero's Job 数论 哈希表 搜索

    原文链接https://www.cnblogs.com/zhouzhendong/p/CF542D.html 题目传送门 - CF542D 题目传送门 - 51Nod1477 题意 定义公式 $J(x ...

  4. Codeforces Round #547 (Div. 3) E. Superhero Battle

    E. Superhero Battle A superhero fights with a monster. The battle consists of rounds, each of which ...

  5. CF1141E Superhero Battle

    A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly n minu ...

  6. CF-1111B-Average Superhero Gang Power

    首先,对于这题我们要知道要删除一个数使平均值最大一定是删除最小的数,然后我们假设删除操作执行了i次,也就是删除最小的i个数.在已知删除操作次数之后求增加操作的次数就容易了,当然是m - i和k * ( ...

  7. Codeforces1141E(E题)Superhero Battle

    A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly nn min ...

  8. E. Superhero Battle

    链接 [https://codeforces.com/contest/1141/problem/E] 题意 怪物开始的生命值,然后第i分钟生命值的变化 问什么时候怪物生命值为非正 分析 有一个巨大的坑 ...

  9. 【CF1141E】Superhero Battle

    \[x*p\ge y\rightarrow x=\lfloor{{y-1}\over p}\rfloor+1\]

随机推荐

  1. 在 Angular6 中使用 HTTP 请求服务端数据

    第一步 准备好api接口地址, 例如 https://api.example.com/api/ 第二步 在根组件 app.module.ts 中引入 HttpClientModule 模块. // a ...

  2. 第四十篇-private,public,protected的区别

    1.public: public表明该数据成员.成员函数是对所有用户开放的,所有用户都可以直接进行调用 2.private: private表示私有,私有的意思就是除了class自己之外,任何人都不可 ...

  3. secureCRT自动断开的解决方法

    转: secureCRT自动断开的解决方法 secureCRT自动断开的解决方法 在secureCRT上登录时,一段时间不用的话会自动断开,必须重新连接,有点麻烦. 有时候服务器端的 /etc/pro ...

  4. LVM备份(2)-创建LVM逻辑卷

    懵逼了几天,对LVM快照备份总算有了个比较清晰的认识 总的来说,就是这样: 1.普通分区备份比较困难,需要转化成LVM逻辑卷进行管理 2.在新创建的LVM逻辑卷上进行业务操作,比如建数据库 3.某个时 ...

  5. GoLang-Rpc编程

    Rpc定义: RPC(Remote Procedure Call,远程过程调用)是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络细节的应用程序通信协议. RPC协议构建于TCP或UDP, ...

  6. Hadoop启动脚本分析

    Hadoop启动脚本分析 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 能看到这篇博客的你估计对Hadoop已经有一个系统的了解了,最起码各种搭建方式你应该是会的,不会也没有关系, ...

  7. MySQL实战45讲学习笔记:日志系统(第二讲)

    一.重要的日志模块:redo log 1.通过酒店掌柜记账思路刨析redo log工作原理 2.InnoDB 的 redo log 是固定大小的 只要赊账记录在了粉板上或写了账本上,之后即使掌柜忘记了 ...

  8. 纯js Ajax 请求

    var XMLHttpReq; function createXMLHttpRequest() { if(window.ActiveXObject ) { try { XMLHttpReq = new ...

  9. NOI-OJ 2.2 ID:6261 汉诺塔

    思路 汉诺塔是递归思想最经典的例子,通过递归不断缩小问题,将n个盘子的问题简化n-1个,直至1个. 三个盘子,分别为A:from,B:to,C:by(A为起点盘,B为目标盘,C为中转盘) 过程 将1- ...

  10. Xml序列化 详解

    http://www.cnblogs.com/kissdodog/archive/2013/12/10/3468385.html