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 --转载 使用SMSSDK实现短信验证:
1.先到http://www.mob.com/#/网站注册账号,然后下载最新的sdk(有Android和iOS两个版本,根据需要进行下载) 2.进入到后台选择SecurityCodeSDk(支持全球短 ...
- 一个中断服务子程序ISR
请看下面的程序(一个中断服务子程序ISR),请指出这段代码的错误.)[中国台湾某著名CPU生产公司2005年面试题] 答案:(1)ISR不能返回一个值.如果你不懂这个,那么是不会被雇用的.(2)ISR ...
- PHP数据类型转换和运算符表达式
一:数据类型的转换 获取类型: gettype($a); 判断是否是某种类型的数据: is_类型名($a); 1.(int)$a; 2.settype($a,int); 二:运算符表达式 1.数学运算 ...
- webstorm-----eslint的配置和使用
https://blog.csdn.net/qq_29329037/article/details/80100450
- c++中的基本知识点
1 class和struct的区别和联系 在c++中,class和struct只有一点不同,它们是可以完全替代使用的.唯一的不同在于,class中的成员默认是private的,而struct中默认是p ...
- Django 初始化数据库
django 初始化数据库 刷新数据库guoguos-MacBook-Pro:mysite guoguo$ python manage.py sqlflushBEGIN;SET FOREIGN_KEY ...
- Android RelativeLayout相对布局
RelativeLayout是相对布局控件:以控件之间相对位置或相对父容器位置进行排列. 相对布局常用属性: 子类控件相对子类控件:值是另外一个控件的id android:layout_above-- ...
- 怎么升级iOS10教程
在前两天的开发者大会上刚推出了iOS10,我介绍一下怎么升级到iOS10的办法.所有人只用一个iPhone就可以升级到iOS10,不需要电脑,也不需要开发者账号. http://bbs.feng.co ...
- leetcode 890. Possible Bipartition
Given a set of N people (numbered 1, 2, ..., N), we would like to split everyone into two groups of ...
- tomcat 1)启动时不识别执行启动命令 2)启动报错 3)关闭不了,用myEclipse启动时显示jvm_bind,端口占用