SPOJ 26108 TRENDGCD - Trending GCD】的更多相关文章

Discription Problem statement is simple. Given A and B you need to calculate S(A,B) . Here, f(n)=n, if n is square free otherwise 0. Also f(1)=1. Input The first line contains one integer T - denoting the number of test cases. T lines follow each con…
题目连接: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],...,…
http://www.spoj.com/problems/PGCD/en/ 题意: 给出a,b区间,求该区间内满足gcd(x,y)=质数的个数. 思路: 设f(n)为 gcd(x,y)=p的个数,那么F(n)为 p | gcd(x,y)的个数,显然可得F(n)=(x/p)*(y/p). 这道题目因为可以是不同的质数,所以需要枚举质数, 但是这样枚举太耗时,所以在这里令t=pk, 这样一来的话,我们只需要预处理u(t/p)的前缀和,之后像之前的题一样分块处理就可以了. #include<iostr…
题目大意: 给定n,m,求有多少组(a,b) 0<a<=n , 0<b<=m , 使得gcd(a,b)= p , p是一个素数 这里本来利用枚举一个个素数,然后利用莫比乌斯反演可以很方便得到答案,但是数据量过大,完全水不过去 题目分析过程(从别人地方抄来的) ans = sigma(p, sigma(d, μ(d) * (n/pd) * (m/pd))) Let s = pd, then ans = sigma(s, sigma(p, μ(s/p) * (n/s) * (m/s))…
2818: Gcd Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 1566  Solved: 691[Submit][Status] Description 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. Input 一个整数N Output 如题 Sample Input 4 Sample Output 4 HINT hint 对于样例(2,2),(2,4),(3,3),(4,2) 1<=N<=…
BUPT2017 wintertraining(15) #5H HDU- 4947 题意 有一个长度为l的数组,现在有m个操作,第1种为1 n d v,给下标x 满足gcd(x,n)=d的\(a_x\)增加v.第2种为2 x,查询\(\sum_{i=1}^x a_i\). 数据范围:\(1\le n,d,v\le2\cdot 10^5,1\le x\le l\) 题解 设\(f_i\)满足\(a_i=\sum_{d|i} f_d\),用树状数组存储\(f_i\)的前缀和. \[a_x+=v\cd…
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…
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),=&…
4491. Primes in GCD Table Problem code: PGCD Johnny has created a table which encodes the results of some operation -- a function of two arguments. But instead of a boring multiplication table of the sort you learn by heart at prep-school, he has cre…