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 ...
随机推荐
- npm 全局配置放在c盘/用户/当前用户/目录下
prefix=D:\Users\Ed\AppData\Roaming\nodejs\npm-globalcache=D:\Users\Ed\AppData\Roaming\npm-cacheregis ...
- EasyNVR无插件直播服务如何配合EasyBMS使用以及实现流媒体管理功能概述
本文转自:https://blog.csdn.net/black_3717/article/details/79769195 功能概要: 1.摄像机的无插件直播: 2.摄像机的低延时直播: 3.摄像机 ...
- AWS:1.相关概念、创建云主机的过程
概念 EC2是弹性的云计算 云主机 也即虚拟机,由分配的CPU.内存.网络和磁盘等资源组成 好处:维护成本低(主机替换).环境升级成本低 AMI:映像 创建云主机的蓝图,指定初始状态1 预装什么操作系 ...
- 动态库对外暴露api的方法
1 windows的动态库 在要export的函数声明的前面加上__declspec(dllexport)标识这个函数是从该dll中export出来给其它模块使用的. declspec是declare ...
- Makefile注意点总结
1 "="和":=" "="号赋值时,如果右边的值里面有未展开的变量,要等到整个Makefile的变量处理完之后,再展开,也就是说,如果该未 ...
- 我的Java开发学习之旅------>Java经典排序算法之归并排序
一.归并排序 归并排序是建立在归并操作上的一种有效的排序算法,该算法是采用分治法(Divide and Conquer)的一个非常典型的应用.将已有序的子序列合并,得到完全有序的序列:即先使每个子序列 ...
- Java for LeetCode 105 Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that ...
- Machine Learning No.11: Recommender System
1. Content based Problem formulation Content Based Recommendations: 2. collaborative filtering algor ...
- WINFROM中自定义控件之绑定数据即时更新
相信在WINFROM中写自定义控件或者用户控件,很多人都多多少少用过点 最近发现一个用户控件,绑定的数据源没办法自动更新,其实以前处理过这类的问题,可是这次遇到又花了1个多小时,所以决定记下来 在用户 ...
- python绘制圆和椭圆
源自:https://blog.csdn.net/petermsh/article/details/78458585 1. 调用包函数绘制圆形Circle和椭圆Ellipse from matplot ...