[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. 剑指Offer_编程题_19

    题目描述 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则依次打印出数字1,2, ...

  2. 金融量化分析【day110】:Pandas-DataFrame索引和切片

    一.实验文档准备 1.安装 tushare pip install tushare 2.启动ipython C:\Users\Administrator>ipython Python 3.7.0 ...

  3. HDU 1049(蠕虫爬井 **)

    题意是一只虫子在深度为 n 的井中,每分钟向上爬 u 单位,下一分钟会下滑 d 单位,问几分钟能爬出井. 本人是直接模拟的,这篇博客的分析比较好一些,应当学习这种分析问题的思路:http://www. ...

  4. oldboy s21day13装饰器和推导式

    #!/usr/bin/env python# -*- coding:utf-8 -*- # 2.请为 func 函数编写一个装饰器,添加上装饰器后可以实现:执行func时,先输入"befor ...

  5. EffectiveC++ 第3章 资源管理

    我根据自己的理解,对原文的精华部分进行了提炼,并在一些难以理解的地方加上了自己的"可能比较准确"的「翻译」. Chapter 3 资源管理 条款13: 以对象管理资源 有时即使你顺 ...

  6. jS处理中英文时间格式化问题

    // datebox里面日期格式化,i18nStr是当前国际化的日期格式,fdate是需要处理的时间,默认为当前时间 function formatDate(i18nStr,fdate) { var ...

  7. webpack4之踩坑总结

    一.先放上项目目录结构 二.问题总结 1.关于process.env.NODE_ENV问题 刚开始的时候,我想在配置文件中使用到这个环境变量,却发现一直获取不到值,晕晕晕,查了资料才知道,这个环境变量 ...

  8. lnmp.org 安装环境的,root权限都没法删除网站文件夹,问题解决-转

    rm -rf删除网站目录时出现rm: cannot remove `.user.ini': Operation not permitted rm -rf删除网站目录时出现rm: cannot remo ...

  9. [正则表达式]PCRE反向分组引用(语法)

    正则表达式中,凡出现圆括号(),括号中的匹配内容就会被认为是一个分组: 根据括号从左边出现的顺序命名分组代号,分组代号由1到n(代号0通常被一些语言用来引用整个表达式匹配的结果,即使这个表达式没有分组 ...

  10. Python-Django 模型层-多表查询-2

    -related_name:基于双下划线的跨表查询,修改反向查询的字段 -related_query_name:基于对象的跨表查询,修改反向查询字段 publish = ForeignKey(Blog ...