题目大意:

已知 $$ 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的更多相关文章

  1. 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 ...

  2. Run Faster-JAVA

    又好久没有写点啥了,平时都忙于工作,忙于应付工作中的问题,各种吸收却并没有好好的消化,该是"反刍"一下的时候了. 本篇名叫"Run Faster,JAVA",其 ...

  3. 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 ...

  4. Java Swing interview

    http://www.careerride.com/Swing-AWT-Interview-Questions.aspx   Swing interview questions and answers ...

  5. 【requireJS源码学习01】了解整个requireJS的结构

    前言 现在工作中基本离不开requireJS这种模块管理工具了,之前一直在用,但是对其原理不甚熟悉,整两天我们来试着学习其源码,而后在探寻其背后的AMD思想吧 于是今天的目标是熟悉requireJS整 ...

  6. Linux监控工具介绍系列——free

    在Linux系统中,我们查看.监控系统内存使用情况,一般最常用的命令就是free.free命令其实非常简单,参数也非常简单,但是里面很多知识点未必你都掌握了.下面总结一下我所了解的free命令.如有不 ...

  7. 【荐】PDO防 SQL注入攻击 原理分析 以及 使用PDO的注意事项

    我们都知道,只要合理正确使用PDO,可以基本上防止SQL注入的产生,本文主要回答以下几个问题: 为什么要使用PDO而不是mysql_connect? 为何PDO能防注入? 使用PDO防注入的时候应该特 ...

  8. SVM实现邮件分类

    首先学习一下svm分类的使用. 主要有以下步骤: Loading and Visualizing Dataj Training Linear SVM Implementing Gaussian Ker ...

  9. About SQLite

    About SQLite See Also... Features When to use SQLite Frequently Asked Questions Well-known Users Boo ...

随机推荐

  1. Python常用变量处理手记(拼接数字,转json)

    1.拼接字符串和数字时,应先把数字做转换 如,bytes(page) 再做拼接:str+page 或者 s = 'abc' print s + str(1) #abc1 使用list和tuple 参考 ...

  2. leetcode笔记:Pow(x, n)

    一. 题目描写叙述 Implement pow(x, n). 二. 题目分析 实现pow(x, n).即求x的n次幂. 最easy想到的方法就是用递归直接求n个x的乘积,这里须要依据n的值,推断结果是 ...

  3. ClassNotFoundException Log

    Studio 运行时异常: Error:Execution failed for task ':app:compileDebugJavaWithJavac'.> Compilation fail ...

  4. 升级webapi依赖的Newtonsoft.json的版本(转)

    随着微软日渐重视开源社区的贡献,微软在自己的产品中往往也会集成开源的第三方库. 比如System.Net.Http.Foramatting.dll 就依赖于Newtonsoft.json v4.5. ...

  5. 如何解决安装好的google浏览器打不开网页的问题?

    1.Google浏览器右上角,三个点,点击一下, 2.点击设置 3.在"搜索引擎"这一栏,选择'管理搜索引擎',右边的倒三角,进入选择界面 4.在其他搜索引擎中选择"百度 ...

  6. 使用服务端的临时密钥,不依赖阿里js的putFIle--》阿里oss

    <!DOCTYPE html> <html lang='en'> <head> <meta charset='UTF-8'> <title> ...

  7. 【linux】如何给sudo的root设置环境变量

    如果系统不能通过root登陆,而是需要使用其他用户sudo的方式登陆root,那么root的环境变量很难设置,修改/etc/profile也没有用.可以通过下面这个方式解决 修改sudoer的配置文件 ...

  8. testng testcase失败重试

    简单介绍 需求场景:测试移动端应用,常会因为点击失效.网络延迟大等原因导致测试脚本失败.这时,需要自动重新运行失败的脚本,直到脚本成功通过或者到达限定重试次数. 解决方案:实现testng的IRetr ...

  9. 在pycharm中执行脚本没有报错但输出显示Redirection is not supported.

    没有新式语法错误,但是输出显示Redirection is not supported.(不支持重定向) 在stockflow中找到是因为从IDE中运行脚本的原因,比如pycharm,所有IDE都提供 ...

  10. 尚学堂xml学习笔记

    1.打开eclipse,文件-新建java project,输入文件的名字,比如输入20181112. 2.对着src右键,选择new-file,输入文件名字,比如:book.xml. 3.开始写.x ...