[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. django-url的分发

    1)url的分发: 1,首先在全局的url里面的路径中写好,你要分发的路径名. 2,并且在你要分发的路径下,创好新的url文件. 在分发的路径名里面,把全局url里面的代码,复制过来 3,最后在浏览器 ...

  2. <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>

    <%String path = request.getContextPath();String basePath = request.getScheme()+"://"+re ...

  3. GO语言系列(四)- 内置函数、闭包与高级数据类型

    一.内置函数.递归函数.闭包 内置函数 1. close:主要用来关闭channel 2. len:用来求长度,比如string.array.slice.map.channel 3. new:用来分配 ...

  4. 轴对称 Navier-Stokes 方程组的点态正则性准则 I

    在 [Lei, Zhen; Zhang, Qi. Criticality of the axially symmetric Navier-Stokes equations. Pacific J. Ma ...

  5. 爬取qq音乐巅峰榜---内地音乐的榜单

    import requestsimport jsonimport sys for i in range(0,10): url = "https://szc.y.qq.com/v8/fcg-b ...

  6. 用sklearn 实现linear regression

    基本的regression算法有四种方法可以实现,分别是下面四种 LinearRegressionRidge (L2 regularization)Lasso (L1 regularization)E ...

  7. luogu P5289 [十二省联考2019]皮配

    传送门 首先考虑一个正常的dp,设\(f_{i,j,k}\)为前\(i\)个学校,\(j\)人在\(\color{#0000FF}{蓝阵营}\),\(k\)人在\(\color{#654321}{吔} ...

  8. 第29月第2天 charles

    1. https://www.jianshu.com/p/55a8c84e0f24

  9. C# - 多线程(基础)

    多线程 基础(Multithreading) 一些基本的关于线程和与其相关的概念 位)的变量赋值,这个操作就是原子性的.因为它可以一次性填充64位的二进制数据到栈上,属于一步完成,不会发生断裂.而假如 ...

  10. django反向解析传参

    这两天写代码总是有反向解析传参顺带复习了一下反向解析,以下是简单的反向解析 以下是我最近写的很多的反向解析传参  想要实现点击修改将这些从数据库读取的内容传到另一个页面就要通过id来查询,那么我们就需 ...