how to run faster
题目大意:
已知 $$ b_i = \sum_{j=1}^n {(i,j)^d [i,j]^c x_j}$$,给定 $b_i$ 求解 $x_i$
解法:
考虑 $f(n) = \sum_{d|n}{fr(d)}$,这样有 $$\sum_{t|i}{fr(t) \sum_{t|j}{j^d x_j} } = b_i$$
容斥得 $fr(i) \sum_{i|j}{j^d x_j}$ 其中 $fr(n)$ 可以容斥得到,再次容斥得到 $x_i$
注意在除以 $fr(i)$ 时会产生无解,多解的情况。
#include <bits/stdc++.h> #define LL long long
#define LD double
#define FOR(i,a,b) for (int i = (a);i <= (b); i++)
#define DFOR(i,a,b) for (int i = (a);i >= (b); i--)
#define debug(x) cerr << "debug: " << (#x) << " = " << (x) <<endl;
#define PI acos(-1)
#define mp make_pair
#define pb push_back
#define itr iterator
#define bit(x) (1LL<<(x))
#define lb(x) ((x)&(-x))
#define sqr(x) ((x)*(x))
#define gn 3
#define l(x) ch[x][0]
#define r(x) ch[x][1]
#define y0 Y0
#define y1 Y1
#define y2 Y2
#define fir first
#define sec second using namespace std; const int N = ;
const LL P = 998244353ll; LL Cc,Dd,fr[N],z[N]; LL qpow(LL x,int n)
{
LL ans=;
for(;n;n>>=,x=x*x%P) if(n&) ans=ans*x%P;
return ans;
} int main()
{
int n,q;
cin >> n >> Cc >> Dd >> q;
FOR(i,,n) fr[i] = qpow(i,(Cc-Dd+P-)%(P-));
FOR(i,,n) for(int j=i+i;j<=n;j+=i) fr[j] = (fr[j]+P-fr[i])%P;
while(q--)
{
FOR(i,,n)
{
scanf("%lld",&z[i]);
z[i] = z[i] * qpow(qpow(i,Dd), P-)%P;
}
FOR(i,,n) for(int j=i+i;j<=n;j+=i) z[j] = (z[j]+P-z[i])%P;
bool nosol = ,mulsol = ;
FOR(i,,n)
{
if(fr[i]== && z[i]!=) nosol = ;
else if(fr[i]== && z[i]==) mulsol = ;
z[i] = z[i] * qpow(fr[i],P-)%P; }
DFOR(i,n,) for(int j=i+i;j<=n;j+=i) z[i] = (z[i]+P-z[j])%P;
if(nosol) puts("-1");
else
{
FOR(i,,n) z[i] = z[i] * qpow(qpow(i,Dd),P-)%P;
FOR(i,,n) printf("%lld ",z[i]);
printf("\n");
}
}
return ;
}
how to run faster的更多相关文章
- 5 Ways to Make Your Hive Queries Run Faster
5 Ways to Make Your Hive Queries Run Faster Technique #1: Use Tez Hive can use the Apache Tez execu ...
- Run Faster-JAVA
又好久没有写点啥了,平时都忙于工作,忙于应付工作中的问题,各种吸收却并没有好好的消化,该是"反刍"一下的时候了. 本篇名叫"Run Faster,JAVA",其 ...
- Faster, more memory efficient and more ordered dictionaries on PyPy
Faster, more memory efficient and more ordered dictionaries on PyPy https://morepypy.blogspot.com/20 ...
- Java Swing interview
http://www.careerride.com/Swing-AWT-Interview-Questions.aspx Swing interview questions and answers ...
- 【requireJS源码学习01】了解整个requireJS的结构
前言 现在工作中基本离不开requireJS这种模块管理工具了,之前一直在用,但是对其原理不甚熟悉,整两天我们来试着学习其源码,而后在探寻其背后的AMD思想吧 于是今天的目标是熟悉requireJS整 ...
- Linux监控工具介绍系列——free
在Linux系统中,我们查看.监控系统内存使用情况,一般最常用的命令就是free.free命令其实非常简单,参数也非常简单,但是里面很多知识点未必你都掌握了.下面总结一下我所了解的free命令.如有不 ...
- 【荐】PDO防 SQL注入攻击 原理分析 以及 使用PDO的注意事项
我们都知道,只要合理正确使用PDO,可以基本上防止SQL注入的产生,本文主要回答以下几个问题: 为什么要使用PDO而不是mysql_connect? 为何PDO能防注入? 使用PDO防注入的时候应该特 ...
- SVM实现邮件分类
首先学习一下svm分类的使用. 主要有以下步骤: Loading and Visualizing Dataj Training Linear SVM Implementing Gaussian Ker ...
- About SQLite
About SQLite See Also... Features When to use SQLite Frequently Asked Questions Well-known Users Boo ...
随机推荐
- iOS项目 -- 模仿花椒直播做的第二层界面完整版
,项目开始做了,好遗憾的是,花椒app有更新了版本,
- 跨平台.NET Core--微软开源方向
跨平台.NET Core--微软开源方向 微软宣布.net开源已经有一段时间了,新的跨平台的.net框架叫.NET Core. 当前支持Windows/Linux/OSX/Docker.官网:h ...
- BZOJ 1597: [Usaco2008 Mar]土地购买 斜率优化
1597: [Usaco2008 Mar]土地购买 Time Limit: 10 Sec Memory Limit: 162 MB Description 农夫John准备扩大他的农场,他正在考虑N ...
- 九度OJ 1032:ZOJ (基础题)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4569 解决:2561 题目描述: 读入一个字符串,字符串中包含ZOJ三个字符,个数不一定相等,按ZOJ的顺序输出,当某个字符用完时,剩下的 ...
- vs2013 solution文件解析
1 定义一个project Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "render", &quo ...
- 20179209《Linux内核原理与分析》第一周作业
如何揭开Linux操作系统的最大面纱 个人认为,真正理解一个操作系统最根本的就是理解其文件系统结构. 自windows图形界面诞生,国内大多数用户都选择了windows操作系统,很多人觉得window ...
- Linux C语言 网络编程(二) server模型
前面介绍了关于连接linux服务端方式,可是服务端的资源是有限的,所以我们通常须要又一次思考,设计一套server模型来处理相应的client的请求. 第一种:并发server.通过主进程统一处理cl ...
- 关于SAP的编码范围
[转自 http://blog.sina.com.cn/s/blog_6466e5f70100ithw.html ] 1.Number Range的通用Tcode:SNRO 2.Number Rang ...
- Database: coursera assignment 1
q.1: Find the titles of all movies directed by Steven Spielberg. select title from moviewhere direct ...
- GDB打印内存命令
用gdb查看内存 格式 x /nfu 参数说明 x是 examine 的缩写 n表示要显示的内存单元的个数 f表示显示方式, 可取如下值 x 按十六进制格式显示变量 d 按十进制格式显示变量 u 按十 ...