首页 > 其他分享 >P5221 Product

P5221 Product

时间:2024-08-19 11:26:15浏览次数:7  
标签:Product prod gcd ll fac P5221 define

P5221 Product

求\(\prod_{i=1}^N\prod_{j=1}^N\frac{lcm(i,j)}{gcd(i,j)}\ (\bmod\ 104857601)\)
如果是上下同时除gcd的话会发现有点困难,但是如果上下同时乘一个gcd,会发现上面变得非常简单。

我们要求的就是分母
\(\prod_{i=1}^N\prod_{j=1}^N{(i,j)^2} (\bmod\ 104857601)\)
直接枚举gcd
\(\prod_{d=1}d^{\sum_{i=1}^{n/d}\sum_{j=1}^{n/d}[(i,j)=1]}\)
可以直接套一个莫反或者转化用仪仗队的做法,反正算d的次方都得带个log。

#include<bits/stdc++.h>
#define fo(i,a,b) for (ll (i)=(a);(i)<=(b);(i)++)
#define fd(i,b,a) for (ll (i)=(b);(i)>=(a);(i)--)
#define eb emplace_back
#define pi pair<ll,ll>
#define mk(x,y) make_pair((x),(y))
#define lc (o<<1)
#define rc ((o<<1)|1)
//#define A puts("Yes")
//#define B puts("No")
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef double db;
const ll mo1=1e9+7;
const ll mo2=1e9+9;
const ll P=131;
const ll Q=13331;
const ll inf=1e9;
const int N=1e6+5;
const ll mo=104857601;
ll n;
int p[N],tot,mu[N];
ll s[N];
bool vis[N];
ll power(ll a,ll b){
	ll t=1,y=a%mo;
	while (b) {
		if (b&1) t=t*y%mo;
		y=y*y%mo;
		b/=2;
	}
	return t;
}
ll gcd(ll a,ll b){
	if (!b) return a;
	return gcd(b,a%b);
}
int main() {
//    freopen("data.in", "r", stdin);
//    freopen("data.out", "w", stdout);

	scanf("%lld",&n);
	
	mu[1]=1;
	fo(i,2,n) {
		if (!vis[i]) {
			p[++tot]=i;
			mu[i]=-1;
		}
		fo(j,1,tot) {
			if (i*p[j]>=N) break;
			vis[i*p[j]]=1;
			if (i%p[j]==0) break;
			mu[i*p[j]]=-mu[i];
		}
	}
	fo(i,1,n) s[i]=s[i-1]+mu[i];

	ll fac=1;
	fo(i,1,n) fac=fac*i%mo;
	fac=power(fac,2*n)%mo;
	
	ll ans=1;
	for (ll lk=1,rk;lk<=n;lk=rk+1) {
		rk=n/(n/lk);
		ll t=0,z=n/lk,f;
		for (ll ld=1,rd;ld<=z;ld=rd+1) {
			rd=z/(z/ld);
			f=(s[rd]-s[ld-1])*(z/ld)*(z/ld);
			t+=f;
		}
		fo(i,lk,rk) ans=ans*power(i,t)%mo;
	}
	
	ans=ans*ans%mo;
	fac=fac*power(ans,mo-2)%mo;
	printf("%lld",fac);
//	printf("%lld\n",ans*ans%mo);
	
	
	
	
    return 0;
    


}

总结,有的时候约分并不一定会变得更加简单,可以观察一下乘上某个数能不能直接求出分子或分母。

标签:Product,prod,gcd,ll,fac,P5221,define
From: https://www.cnblogs.com/ganking/p/18366981

相关文章

  • SciTech-BigDataAIML-LLM-Transformer Series-Self-Attention:由Dot-Product(向量点乘)
    SelfAttention:由Dot-Product(向量点乘)说起https://lulaoshi.info/deep-learning/attention/transformer-attention.html#self-attention-从向量点乘说起Transformer[1]论文提出了一种Self-Attention(自注意力机制),Self-Attention的最核心的公式为:\(\large\begin{align*}......
  • AGC182 C - Sum of Number of Divisors of Product
    题目大意:求长度为1,2,...N,的好序列因数个数。好序列满足每个元素\(1\leqx\leqM\)\(N\leq1e18,M\leq16\)很容易想到维护所有好序列质因数的指数+1的乘积。\(\prodb_i,1\leqi\leq6\).考虑每个数对这个乘积的影响。假设我们只有2,3,5这三个质数,序列末端添加15,......
  • Leetcode: 1484. Groups Sold Products By The Date
    题目要求如下:输入的数据为要求按照日期查询出每日销售数量及相应产品的名称,并按照字符顺序进行排序。下面是实现的代码:importpandasaspddefcategorize_products(activities:pd.DataFrame)->pd.DataFrame:val=activities.drop_duplicates().groupby("sell......
  • 【Python】笛卡尔积 intertools.product()
    一、题目Thistoolcomputesthecartesianproductofinputiterables.Itisequivalenttonestedfor-loops.Forexample,product(A,B)returnsthesameas((x,y)forxinAfroyinB).SampleCodefromitertoolsimportproductprint(list(product([1,2,3],......
  • A. Least Product
    原题链接题解1.如果初始乘起来小于等于0,由于操作无法使该乘积更小,所以不用再修改2.否则代表初始值大于零,随便找一个地方改成03.注意由于a很大,所以要用统计的方式来判断乘积的性质code#include<bits/stdc++.h>#definelllonglongusingnamespacestd;voidsolve(){......
  • SciTech-Mathematics-Probability+Statistics-Dot products, cosine similarity, text
    Dotproducts,cosinesimilarity,textvectorshttps://dev.to/sayemmh/dot-products-cosine-similarity-text-vectors-2lo4SayemHoque,PostedonOct20,2022Dotproducts,cosinesimilarity,textvectorsCosinesimilarityisameasurebetweentwosingledimen......
  • D. Maximum Sum of Products
    链接https://codeforces.com/problemset/problem/1519/D题目分析总的来说不算难的一道题,主要是敢写就行,控制在O(n^2),枚举中心点,分成两类:一类是奇数,一类是偶数对称就行。代码#define_CRT_SECURE_NO_WARNINGS#include<iostream>#include<vector>#include<algorithm>#in......
  • zzuli-production practice 2
    1.安装配置Redis并练习基础命令操作官网:https://redis.io中文网:Redis中文网解压直接可以使用:redis.windows.conf:配置文件redis-cli.exe:redis的客户端redis-server.exe:redis服务器端安装Redis服务1、由于上面虽然启动了redis,但是只要一关闭cmd窗口,redis服务就会......
  • [LeetCode] 238. Product of Array Except Self
    坑真的很多,首先要处理全零reduce没有值typeerror的问题。classSolution:defproductExceptSelf(self,nums:List[int])->List[int]:total=reduce(mul,nums)ret=[]iftotal==0:try:total=reduce(mul,[......
  • [题解]AT_arc116_b [ARC116B] Products of Min-Max
    思路我们容易可以得到一个朴素的做法,首先对\(a\)数组排序,然后枚举最大值和最小值\(a_i,a_j\),那么对于中间的元素都有选与不选两种情况,得到答案:\[\sum_{i=1}^{n}(a_i\timesa_i+(\sum_{j=i+1}^{n}a_i\timesa_j\times2^{j-i-1}))\]然后对这个式子......