题目大意: 给定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))…
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…
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…
SPOJ4491. 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…
这题肝了三四天,其他啥也没做... 传送门 然后...双倍经验 简单版 不知道为什么会脑抽去帮 LZ_101 大佬验题... 题目和被 A 穿的 PGCD 一样,数据范围变成大概 2e11 ... 于是我们就要考虑用更加优秀的做法去解决这道题了 首先我们得想到 PGCD 中最优秀的解法: \[ANS=\sum_{i=1}^{n} \lfloor {n\over d}\rfloor \lfloor {m\over d} \rfloor \sum_{p∈ prime ,p|d} \mu({p\ove…
题目链接:https://vjudge.net/problem/SPOJ-PGCD 题目大意: 给定 \(N\) 和 \(M\),求满足 \((1 \le x \le N), (1 \le y \le M)\),且 \(gcd(x,y)\) 为素数的 \((x,y)\) 的对数. 知识点: 莫比乌斯反演 解题思路: 设 \(g(p)\) 表示满足 \((1 \le x \le N), (1 \le y \le M)\),且 \(gcd(x,y) = p\) 的 \((x,y)\) 的对数.直接求…
一通套路之后得到 求出中间那个函数的前缀和的话就可以整除分块了. 暴力求的话复杂度其实很优秀了,大约在n~nlogn之间. 不过可以线性筛做到严格线性.考虑其最小质因子,如果是平方因子那么只有其有贡献,否则由于多了一个质因子,将函数值取反并加上该质因子贡献. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #includ…
传送门:Primes in GCD Table 题意:给定两个数和,其中,,求为质数的有多少对?其中和的范围是. 分析:这题不能枚举质数来进行莫比乌斯反演,得预处理出∑υ(n/p)(n%p==0). #pragma comment(linker,"/STACK:1024000000,1024000000") #include <cstdio> #include <cstring> #include <string> #include <cmat…
C. GCD Table The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both…
A. GCD Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the…
C. GCD Table Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/583/problem/C Description The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest c…
题目链接:http://codeforces.com/contest/583/problem/C C. GCD Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The GCD table G of size n × n for an array of positive integers a of length n …
A. GCD Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the…
2818: Gcd Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 4436  Solved: 1957[Submit][Status][Discuss] Description 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. 1<=N<=10^7 uva上做过gcd(x,y)=1的题 gcd(x,y)=p ---> gcd(x/p,y/p)=1 每个质数做一遍行了 答案是欧拉函数的前缀和*2…
Description 神犇YY虐完数论后给傻×kAc出了一题给定N, M,求1<=x<=N, 1<=y<=M且gcd(x, y)为质数的(x, y)有多少对kAc这种 傻×必然不会了,于是向你来请教……多组输入 Input 第一行一个整数T 表述数据组数接下来T行,每行两个正整数,表示N, M Output T行,每行一个整数表示第i组数据的结果 Sample Input 2 10 10 100 100 Sample Output 30 2791 HINT T = 10000 N…
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 题意 :求满足gcd(i , j)是素数(1 <= i <= n && 1 <= j <= m)二元组(i , j)个数. 很值得总结的题... 首先得会一点前提东西 ...先简单说下Mobius反演,就是偏序集上的容斥原理. 定义 F(n) = sigma (G(d))   d | n 那么G(n) = sigma…
题目连接: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],...,…
今天做的一个很有成就感的题目,虽然经过我一个上午的痛苦挣扎,但是我觉得这个时间还是花的挺有意义的. 题目的意思是给你a和b两个数(范围是10^7),从1-a选一个数x,从1-b中间选择一个数,问你能选出来gcd(a,b)=素数 的方案数有多少? 这是一类典型的gcd统计问题,也是十分有代表性的一个题目. 首先看到这个题目的时候我也不知道如何入手呢,任何的想法都逃不过T的阴影. 后来去网上看了各路神牛的题解我才稍稍明白了过来呢. 这个题目主要用到的只是就是莫比乌斯反演(Mobius). 其本质是容…
题目链接:http://codeforces.com/problemset/problem/582/A 网上很多题解,就不说了,直接贴代码= = 官方题解: http://codeforces.com/blog/entry/20692 #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include &…
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 给定一个序列,a[1 ..k],问是否存在(i , j)使得 GCD(i , j + r - 1) = a[r]  (k>=r >=1),其中 i <= n && j + k - 1 <= m http://codeforces.com/contest/338/problem/D 首先容易知道row = lcm (a[…
主题链接:点击打开链接 特定n*m矩阵,[i,j]分值为gcd(i,j) 给定一个k长的序列,问能否匹配上 矩阵的某一行的连续k个元素 思路: 我们要求出一个解(i,j) 使得 i<=n && j<=m 此时输出 YES 对于j j % b[0] = 0 j+1 % b[1] = 0 ··· j+l % b[l] = 0 依据定理:若 a == b (mod n) => (a+c) == b+c (mod n) 所以将上式变换为 j % b[0] = 0 j % b[1]…
什么都不会只能学数论QAQ 英文原题不贴了 题意: 有一张N*M的表格,i行j列的元素是gcd(i,j)读入一个长度为k,元素大小不超过10^12的序列a[1..k],问这个序列是否在表格的某一行中出现过 1<=N,M<=10^121<=k<=10^4 恩 首先显然x=lcm(a[i]) 然后(y+i-1)%a[i]==0 即y%[i]=1-n 然后就神奇地变成了中国剩余定理 求出x和y后判无解即可,情况比较多 首先如果x和y超过n,m的范围或<0显然不对 然后注意枚举i看g…
http://codeforces.com/problemset/problem/338/D 题意: 有一张n*m的表格,其中第i行第j列的数为gcd(i,j) 给出k个数 问在这张表格中是否 有某一行中连续的某一部分 就是 这k个数 题意转化: 是否存在 一对i,j 满足gcd(i,j)=a1,gcd(i,j+1)=a2,…… gcd(i,j+k-1)=ak 直观上感觉: i要满足的必要条件是 i |  lcm(a1,a2……ak) j要满足的必要条件是 j= a1*k1,j+1=a2*k2……
题意:给你n*n gcd表中的所有数(以任意顺序) ,求对角线上的n个数分别是什么.gcd表定义如下,先将n个数填在对角线的上,然后将各个格子填上对应对角线上的数的gcd值,也就是V[i][j]=gcd(V[i][i],V[j][j]) 题解:观察发现有很多重复的数,而且最大的那个数必然是对角线上的数.所以用map存数据,map.first 存数,map.second存次数. 一开始发现了如果最大的数N重复x*x次,那么对角线上就有x个N,于是每次输出根号次最大的数,用这个规律wa23了(233…
传送门 简单的中国剩余定理练习. 首先行数一定是$lcm$,然后只要确定最小的列数就能判定解合不合法了. 我们可以得到线性模方程组: $y \equiv 0 \pmod{a_1}$ $y+1 \equiv 0 \pmod {a_2}$ $y+2 \equiv 0 \pmod {a_3}$ $...$ $y+n \equiv 0 \pmod {a_{n+1}}$ 然后CRT搞出来一组解,暴力判判就OK了. //CF338D //by Cydiater //2017.2.20 #include &l…
[题目描述] 有一张N,M<=10^12的表格,i行j列的元素是gcd(i,j) 读入一个长度不超过10^4,元素不超过10^12的序列a[1..k],问是否在某一行中出现过 [题解] 要保证gcd(x,y)=a[i],显然x=lcm(a[1],a[2]……a[k]) 然后y%a[1]=0,即(y+i-1)%a[i]=0 即y%a[1]=0 y%a[2]=-1 …… y%a[n]=-(n-1) 这就转化为了中国剩余定理 求出y之后,只需验证gcd(x,y+i-1)=a[i]即可 /*******…
对角线上的元素就是a[i],而且在所在行和列中最大, 首先可以确定的是最大的元素一定是a[i]之一,这让人想到到了排序. 经过排序后,每次选最大的数字,如果不是之前更大数字的gcd,那么只能是a[i]之一. div2路漫漫... #include<bits/stdc++.h> using namespace std; typedef int ll; ll a[]; *]; ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; } map<int,int&g…
原题链接:http://codeforces.com/problemset/problem/583/C 题意: 大概就是给你个gcd表,让你还原整个序列. 题解: 由$GCD(a,a)=a$,我们知道最大的那个数一定是原序列中的数,然后每次从集合中选取最大的数出来,和已经构造好的序列进行gcd,删除gcd出来的值即可. 代码: #include<iostream> #include<cstring> #include<map> #include<cstdio>…
[题目链接] 点击打开链接 [算法] G中最大的数一定也是a中最大的数.          G中次大的数一定也是a中次大的数. 第三.第四可能是由最大和次大的gcd产生的 那么就不难想到下面的算法: 1. 令p为G中最大的数.在G中删除p,a中加入p.         2 . 对于a中的所有其他数(设为q),在G中删除2个gcd(p, q). 3. 若G为空则结束:否则回到(1). [代码] #include<bits/stdc++.h> using namespace std; #defin…
[链接] 我是链接,点我呀:) [题意] 给你一个数组A[]经过a[i][j] = gcd(A[i],A[j])的规则生成的二维数组 让你求出原数组A [题解] 我们假设原数组是A 然后让A数组满足A[i]<Ai+1 然后我们要先想到一个不等式 a[i][j]=gcd(A[i],A[j])<=A[min(i,j)] 而miin(i,j)<=n 则a[i][j]<=A[n] 所以a[i][j]里面的最大值就是A[n] 之后,我们把gcd(A[n],A[n])删掉 这样剩余的n*n-1…