hdu 4983 Goffi and GCD(数论)】的更多相关文章

题目链接:hdu 4983 Goffi and GCD 题目大意:求有多少对元组满足题目中的公式. 解题思路: n = 1或者k=2时:答案为1 k > 2时:答案为0(n≠1) k = 1时:须要计算,枚举n的因子.令因子k=gcd(n−a,n, 那么还有一边的gcd(n−b,n)=nk才干满足相乘等n.满足k=gcd(n−a,n)的a的个数即为ϕ(n/s),欧拉有o(n‾‾√的算法 #include <cstdio> #include <cstring> #include…
HDU 4983 Goffi and GCD 思路:数论题.假设k为2和n为1.那么仅仅可能1种.其它的k > 2就是0种,那么事实上仅仅要考虑k = 1的情况了.k = 1的时候,枚举n的因子,然后等于求该因子满足的个数,那么gcd(x, n) = 该因子的个数为phi(n / 该因子),然后再利用乘法原理计算就可以 代码: #include <cstdio> #include <cstring> #include <cmath> typedef long lo…
Problem Description Goffi is doing his math homework and he finds an equality on his text book: gcd(n−a,n)×gcd(n−b,n)=nk. Goffi wants to know the number of (a,b) satisfy the equality, if n and k are given and 1≤a,b≤n. Note: gcd(a,b) means greatest co…
题目大意:给你N和K,问有多少个数对满足gcd(N-A,N)*gcd(N-B,N)=N^K.题解:由于 gcd(a, N) <= N,于是 K>2 都是无解,K=2 只有一个解 A=B=N,只要考虑K=1的情况就好了其实上式和这个是等价的gcd(A,N)*gcd(B,N)=N^K,我们枚举gcd(A,N)=g,那么gcd(B,N)=N/g.问题转化为统计满足 gcd(A, N)=g的A的个数.这个答案就是 ɸ(N/g),只要枚举 N 的 约数就可以了.答案是 Σɸ(N/g)*ɸ(g)(g|N)…
题意说的非常清楚,即求满足gcd(n-a, n)*gcd(n-b, n) = n^k的(a, b)的不同对数.显然gcd(n-a, n)<=n, gcd(n-b, n)<=n.因此当n不为1时,当k>2时,不存在满足条件的(a,b).而当k=2时,仅存在(n, n)满足条件.因此仅剩n=1以及k=1需要单独讨论:当n = 1时,无论k为何值,均有且仅有(1,1)满足条件,此时结果为1:当k = 1时,即gcd(n-a, n)*gcd(n-b, n) = n,则令gcd(n-a, n) =…
HDU 4981 Goffi and Median 思路:排序就能够得到中间数.然后总和和中间数*n比較一下就可以 代码: #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const int N = 1005; int n, a[N], sum; int main() { while (~scanf("%d…
HDU 4982 Goffi and Squary Partition 思路:直接从全然平方数往下找,然后推断是否能构造出该全然平方数,假设能够就是yes,假设都不行就是no.注意构造时候的推断,因为枚举一个全然平方数.剩下数字为kk.构造的时候要保证数字不反复 代码: #include <cstdio> #include <cstring> #include <cmath> int n, k; bool judge(int num) { int yu = num *…
Different GCD Subarray Query Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 221    Accepted Submission(s): 58 Problem Description This is a simple problem. The teacher gives Bob a list of probl…
CA Loves GCD  Accepts: 64  Submissions: 535  Time Limit: 6000/3000 MS (Java/Others)  Memory Limit: 262144/262144 K (Java/Others) 问题描述 CA喜欢是一个热爱党和人民的优秀同♂志,所以他也非常喜欢GCD(请在输入法中输入GCD得到CA喜欢GCD的原因). 现在他有N个不同的数,每次他会从中选出若干个(至少一个数),求出所有数的GCD然后放回去. 为了使自己不会无聊,CA…
Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论 题意 给你一段数,然后小明去猜某一区间内的gcd,这里不一定是准确值,如果在这个区间内改变一个数的值(注意不是真的改变),使得这个区间的gcd是小明所猜的数也算小明猜对.另一种操作就是真的修改某一点的值. 解题思路 这里我们使用线段树,维护区间内的gcd,判断的时候需要判断这个区间的左右子区间的gcd是不是小明猜的数的倍数或者就是小明猜的数,如果是,那么小明猜对了.否则就需要进入这个区间…
CA Loves GCD 题目链接: http://acm.hust.edu.cn/vjudge/contest/123316#problem/B Description CA is a fine comrade who loves the party and people; inevitably she loves GCD (greatest common divisor) too. Now, there are different numbers. Each time, CA will se…
题目链接 给n个数, m个询问, 每个询问给出[l, r], 问你对于任意i, j.gcd(a[i], a[j]) L <= i < j <= R的和. 假设两个数的公约数有b1, b2, b2...bn, 那么这两个数的最大公约数就是phi[b1] + phi[b2] + phi[b3]...+phi[bn]. 知道这个就可以用莫队了, 具体看代码. #include <bits/stdc++.h> using namespace std; #define pb(x) pu…
又见GCD Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 19497    Accepted Submission(s): 8129 Problem Description 有三个正整数a,b,c(0<a,b,c<10^6),其中c不等于b.若a和c的最大公约数为b,现已知a和b,求满足条件的最小的c.   Input 第一行输入一个…
A frog has just learned some number theory, and can't wait to show his ability to his girlfriend. Now the frog is sitting on a grid map of infinite rows and columns. Rows are numbered 1,2,⋯from the bottom, so are the columns. At first the frog is sit…
Revenge of GCD Problem Description In mathematics, the greatest common divisor (gcd), also known as the greatest common factor (gcf), highest common factor (hcf), or greatest common measure (gcm), of two or more integers (when at least one of them is…
http://acm.hdu.edu.cn/showproblem.php?pid=4983 求有多少对元组满足题目中的公式. 对于K=1的情况,等价于gcd(A, N) * gcd(B, N) = N,我们枚举 gcd(A, N) = g,那么gcd(B, N) = N / g.问题转化为统计满足 gcd(A, N) = g 的 A 的个数.这个答案就是 ɸ(N/g) 只要枚举 N 的 约数就可以了.答案是 Σɸ(N/g)*ɸ(g) g | N 暴力即可 #include <cstdio>…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5019 Problem Description In mathematics, the greatest common divisor (gcd), also known as the greatest common factor (gcf), highest common factor (hcf), or greatest common measure (gcm), of two or more i…
题目链接:http://acm.swust.edu.cn/problem/1125/ Time limit(ms): 1000 Memory limit(kb): 65535   Description 哈特13最近在学习数论问题,然后他智商太低,并学不懂.这不,他又碰到不会的题了.题意非常简单: 有n个数字,求出这些数字中两两最大公约数的最大值.你一定要帮助他解决这个问题啊. Input 多组输入,约25组,直到文件末尾.每组数据占2行,第一行为数字个数n,2<=n<=100000第二行即为…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2114 自己对数论一窍不通啊现在,做了一道水题,贴出来吧...主要是让自己记住这个公式: 前n项和的立方公式为   : s(n)=(n*(n+1)/2)^2; 前n项和的平方公式为:s(n)=n*(n+1)(2*n+1)/6; 代码: #include<iostream> #include<cstdlib> #include<cstdio> using namespace s…
又见GCD Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 18480    Accepted Submission(s): 7708 Problem Description 有三个正整数a,b,c(0<a,b,c<10^6),其中c不等于b.若a和c的最大公约数为b,现已知a和b,求满足条件的最小的c.   Input 第一行输入一…
Sum Of Gcd 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4676 Description Given you a sequence of number a1, a2, ..., an, which is a permutation of 1...n. You need to answer some queries, each with the following format: Give you two numbers L, R, y…
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5656 bc:http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=683&pid=1002 CA Loves GCD Accepts: 64    Submissions: 535 Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/2…
CA Loves GCD 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5656 Description CA is a fine comrade who loves the party and people; inevitably she loves GCD (greatest common divisor) too. Now, there are N different numbers. Each time, CA will select s…
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=4676 Sum Of Gcd Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 908    Accepted Submission(s): 438 Problem Description Given you a sequence of numb…
Diophantus of Alexandria Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2269    Accepted Submission(s): 851 Problem Description Diophantus of Alexandria was an egypt mathematician living in Ale…
Goffi and Squary Partition Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Submission(s): Problem Description Recently, Goffi is interested in squary partition of integers. A set X of k distinct positive i…
Problem about GCD Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 470    Accepted Submission(s): 77 Problem Description Given integer m. Find multiplication of all 1<=a<=m such gcd(a, m)=1 (cop…
离线+分块!! 思路:序列a[1],a[2],a[3]……a[n] num[i]表示区间[L,R]中是i的倍数的个数:euler[i]表示i的欧拉函数值. 则区间的GCD之和sum=∑(C(num[i],2)*euler[i]).当增加一个数时,若有约数j,则只需加上num[j]*euler[j],之后再num[j]++; 反之亦然!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #inc…
题意: 从区间[1, b]和[1, d]中分别选一个x, y,使得gcd(x, y) = k, 求满足条件的xy的对数(不区分xy的顺序) 分析: 虽然之前写过一个莫比乌斯反演的总结,可遇到这道题还是不知道怎么应用. 这里有关于莫比乌斯反演的知识,而且最后的例题中就有这道题并给出了公式的推导. 在最后的例题2中有个重要的结论: #include <cstdio> #include <algorithm> typedef long long LL; ; ], vis[maxn + ]…
Sqrt Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5752 Description Let's define the function f(n)=⌊n−−√⌋. Bo wanted to know the minimum number y which satisfies fy(n)=1. note:f1(n)=f(n),fy(n)=f(fy−1(n)) It is a pity that Bo can only use 1 unit…