[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. python中的三元运算

    一.三元运算符 三元运算符就是在赋值变量的时候,可以直接加判断,然后赋值 格式:[on_true] if [expression] else [on_false] res = 值1 if 条件 els ...

  2. 老男孩Python全栈学习 S9 日常作业 004

    1.写代码,有如下列表,按照要求实现每一个功能 li = ["alex", "WuSir", "ritian", "barry&q ...

  3. HTML(四)HTML常用标签(a,img)

    a元素 <a>元素 (或HTML锚元素, Anchor Element)通常用来表示一个锚点/链接.但严格来说,<a>元素不是一个链接,而是超文本锚点,可以链接到一个新文件.用 ...

  4. iTOP-4418开发板Qt系统下运行摄像头测试程序

    编译环境:Ubuntu 12.04 交叉编译工具链:gcc 4.4.1 一.添加编译器的环境变量 打开~/.bashrc文件,修改环境变量,如下图:   修改完后,更新环境变量,使用命令”source ...

  5. 分布式系列四: HTTP及HTTPS协议

    分布式系列四: HTTP及HTTPS协议 非常全面的一篇HTTP的文章: 关于HTTP协议,一篇就够了 还有一个帮助理解HTTPS的文章: 也许,这样理解HTTPS更容易 本文的一些描述摘自这篇文章 ...

  6. CF1139C Edgy Trees

    题目地址:CF1139C Edgy Trees 红黑树 \(ans\) 应该等于总数(\(n^k\))减去不含黑色边的序列数量 不含黑色边就意味着一个序列只能在一个红色联通块中 一个红色联通块中的序列 ...

  7. ES6 + Webpack + React + Babel 如何在低版本浏览器上愉快的玩耍

    https://blog.csdn.net/a324539017/article/details/52824189

  8. C++设计模式——组合模式

    问题描述 上图,是一个公司的组织结构图,总部下面有多个子公司,同时总部也有各个部门,子公司下面有多个部门.如果对这样的公司开发一个OA系统,作为程序员的你,如何设计这个OA系统呢?先不说如何设计实现, ...

  9. 使用numpy 将0-1000 中所有偶数转成0 所有奇数转成1

  10. javascript数组去重 String字符串去掉两端空格 javascript Array二分法排序 比较 javascript 求和

    通过原形添加方法: ==================数组去重(对象去重法)======================= Array.prototype.unique=function(){ va ...