SPOJ GCDMAT - GCD OF MATRIX】的更多相关文章

3871. GCD Extreme Problem code: GCDEX Given the value of N, you will have to find the value of G. The meaning of G is given in the following code G=0; for(k=i;k< N;k++) for(j=i+1;j<=N;j++) { G+=gcd(k,j); } /*Here gcd() is a function that finds the g…
题目大意给出一个n,求sum(gcd(i,j),<i<j<=n); 可以明显的看出来s[n]=s[n-]+f[n]; f[n]=sum(gcd(i,n),<i<n); 现在麻烦的是求f[n] gcd(x,n)的值都是n的约数,则f[n]= sum{i*g(n,i),i是n的约数},注意到gcd(x,n)=i的 充要条件是gcd(x/i,n/i)=,因此满足条件的 x/i有phi(n/i)个,说明gcd(n,i)=phi(n/i). f[n]=sum{i*phi(n/i),=&…
题目链接 \(Description\) 一个国家有1~n座城市,其中一些城市之间可以修建高速公路(无自环和重边). 求有多少种方案,选择修建一些高速公路,组成一个交通网络,使得任意两座城市之间恰好只有一条路径. \(Solution\) 生成树计数 直接上Matrix Tree 无解情况别忘了判 MatrixTree定理大体见这吧,证明别的应用什么的先不管了. 基尔霍夫矩阵=度数矩阵-边矩阵. #include <cmath> #include <cstdio> #include…
You are given N(1<=N<=100000) integers. Each integer is square free(meaning it has no divisor which is a square number except 1) and all the prime factors are less than 50. You have to find out the number of pairs are there such that their gcd is 1…
承接一下洛咕上的题解,这里基本就是谈谈优化,放个代码的 我们发现这里的常数主要来自于除法,那么我们优化除法次数,把所有的 \(n/1...n/s\) (\(s=\sqrt n\))存下来,然后归并排(其实就是 merge 一下),最后 unique 去个重,然后就可以进行小常数的数论分块了 //by Judge #pragma GCC optimize("Ofast") #include<bits/stdc++.h> #define Rg register #define…
P1829 [国家集训队]Crash的数字表格 / JZPTAB 题意:求 \({\rm S}(n,m)=\sum\limits_{i=1}^n\sum\limits_{j=1}^m{\rm lcm}(i,j)\) ,对 \(20101009\) 取模. \(x/y\) 等价于 \(\left\lfloor \dfrac xy \right\rfloor\) ,并且设 \(n\le m\) \[\begin{aligned} \sum_{i=1}^n\sum_{j=1}^m{\rm lcm}(i…
发现其实有关gcd的题目还是挺多的,这里根据做题顺序写出8题. [bzoj2818: Gcd] gcd(x,y)=质数, 1<=x,y<=n的对数 做这题的时候,懂得了一个非常重要的转化:求(x, y) = k, 1 <= x, y <= n的对数等于求(x, y) = 1, 1 <= x, y <= n/k的对数!所以,枚举每个质数p(线性筛素数的方法见:线性时间内筛素数和欧拉函数),然后求(x, y) = 1, 1 <= x, y <= n/p的个数.…
原理应该不用多讲了,自己百度就可以. C++实现: #include <iostream> #include <string> #include <memory.h> #include <cstdlib> #include <ctime> #include <cstdio> #include <cmath> using namespace std; //定义一些常变量 ; //定义集合{a,b,...,z}的26个英文字母…
SPOJ Problem Set (classical) 7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N lattice. One corner is at (0,0,0) and the opposite one is at (N,N,N). How many lattice points are visible from corner at (0,0,0) ? A point X is visible…
题目连接:http://www.spoj.com/problems/LGLOVE/ 题意:给出n个初始序列a[1],a[2],...,a[n],b[i]表示LCM(1,2,3,...,a[i]),即1~a[i]的最小公倍数 然后给出三种操作,注意:0<=i,j<n 0 i j p :a[i]~a[j]都加上p 1 i j :求LCM(b[i],b[i+1],...,b[j]) 2 i j :求GCD(b[i],b[i+1],...,b[j]) 思路: 求LCM(b[i],b[i+1],...,…