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 ...
随机推荐
- iOSPOI检索详细总结
iOS百度地图路径规划和POI检索详细总结 路径规划.png 百度地图的使用 百度地图API的导入网上说了许多坑,不过我遇到的比较少,这里就放两个比较常见的吧.坑一: 奥联WIFI_xcodeproj ...
- java 给多人发送、抄送
关键技术: 1.MimeMessage的setRecipients方法设置邮件的收件人,其中Message.RecipientType.TO常量表示收件人类型是邮件接收者,Message.Recipi ...
- 基于EasyNVR+EasyDSS H5视频直播二次开发实现业务需求:直接使用播放页面
之前的"网页直播.微信直播技术解决方案:EasyNVR与EasyDSS流媒体服务器组合之区分不同场景下的easynvr"有介绍一些功能.由于客户需求,我们定制一下功能.给该套方案添 ...
- 九度OJ 1010:A + B (字符串处理)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:7166 解决:3646 题目描述: 读入两个小于100的正整数A和B,计算A+B. 需要注意的是:A和B的每一位数字由对应的英文单词给出. ...
- Software-defined networking
Software-defined networking administrators to programmatically initialize, control, change, and mana ...
- Asynchronous_method_invocation 异步方法调用 让步 yielding
zh.wikipedia.org/wiki/同步 [同步不同事件发生 时间一致] 同步(英语:Synchronization),指在一个系统中所发生的事件(event),之间进行协调,在时间上出现一致 ...
- Linux PPTP拨号
试验环境:Linux marsboard 3.4.90 #9 SMP PREEMPT Thu Mar 3 18:28:43 CST 2016 armv7l armv7l armv7l GNU/Linu ...
- 认识与入门 Markdown
Markdown 是一种轻量级的「标记语言」,它的优点很多,目前也被越来越多的写作爱好者,撰稿者广泛使用.看到这里请不要被「标记」.「语言」所迷惑,Markdown 的语法十分简单.常用的标记符号也不 ...
- 【Leetcode-easy】Remove Element
思路:遍历数组,count保存下一个元素的位置,如果不与该元素相同,那么将该数保存在count位置,并且count++,否则,继续遍历. public int removeElement(int[] ...
- Automator 实例:使用快捷键 实现 快速在当前路径 打开 iTerm
1. 在 finder -> 应用程序 或 通过 Spotlight 打开:Automator.app 2. 选择新建 “服务” 3. 设置服务,见下图,设置完成之后,command + s 保 ...