题目链接: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 <cmath>
#include <algorithm> using namespace std;
const int maxn = 1e5;
const int MOD = 1e9+7;
typedef long long ll; ll ans;
int N, K, M;
int np, pri[maxn+5], vis[maxn+5];
int nf, fact[maxn+5], coun[maxn+5]; void prime_table (int n) {
np = 0;
memset(vis, 0, sizeof(vis)); for (int i = 2; i <= n; i++) {
if (vis[i])
continue;
pri[np++] = i;
for (int j = 2 * i; j <= n; j += i)
vis[j] = 1;
}
} void div_factor(int n) {
nf = 0;
for (int i = 0; i < np; i++) {
if (n % pri[i] == 0) {
coun[nf] = 0;
while (n % pri[i] == 0) {
coun[nf]++;
n /= pri[i];
}
fact[nf++] = pri[i];
}
} if (n != 1) {
coun[nf] = 1;
fact[nf++] = n;
}
} int euler_phi(int n) {
int m = (int)sqrt((double)n+0.5);
int ret = n;
for (int i = 2; i <= m; i++) {
if (n % i == 0) {
ret = ret / i * (i-1);
while (n%i==0)
n /= i;
}
} if (n > 1)
ret = ret / n * (n - 1);
return ret;
} ll add (int s) {
ll a = euler_phi(N/s);
ll b = euler_phi(s);
ll ret = a * b * 2; if (s == N / s)
ret /= 2;
return ret;
} void dfs (int s, int d) {
if (s > M)
return; if (d == nf) {
ans = (ans + add(s)) % MOD;
return;
} for (int i = 0; i <= coun[d]; i++) {
dfs(s, d+1);
s *= fact[d];
}
} int solve () {
ans = 0;
M = (int)sqrt((double)N);
div_factor(N);
dfs (1, 0);
return ans % MOD;
} int main () {
prime_table(maxn);
while (scanf("%d%d", &N, &K) == 2) {
if (N == 1)
printf("1\n");
else if (K > 2)
printf("0\n");
else if (K == 2)
printf("1\n");
else
printf("%d\n", solve());
}
return 0;
}

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

  1. HDU 4983 Goffi and GCD(数论)

    HDU 4983 Goffi and GCD 思路:数论题.假设k为2和n为1.那么仅仅可能1种.其它的k > 2就是0种,那么事实上仅仅要考虑k = 1的情况了.k = 1的时候,枚举n的因子 ...

  2. hdu 4983 Goffi and GCD(欧拉函数)

    Problem Description Goffi is doing his math homework and he finds an equality on his text book: gcd( ...

  3. HDU 4983 Goffi and GCD

    题目大意:给你N和K,问有多少个数对满足gcd(N-A,N)*gcd(N-B,N)=N^K.题解:由于 gcd(a, N) <= N,于是 K>2 都是无解,K=2 只有一个解 A=B=N ...

  4. 【HDOJ】4983 Goffi and GCD

    题意说的非常清楚,即求满足gcd(n-a, n)*gcd(n-b, n) = n^k的(a, b)的不同对数.显然gcd(n-a, n)<=n, gcd(n-b, n)<=n.因此当n不为 ...

  5. HDU 4981 Goffi and Median(水)

    HDU 4981 Goffi and Median 思路:排序就能够得到中间数.然后总和和中间数*n比較一下就可以 代码: #include <cstdio> #include <c ...

  6. HDU 4982 Goffi and Squary Partition(推理)

    HDU 4982 Goffi and Squary Partition 思路:直接从全然平方数往下找,然后推断是否能构造出该全然平方数,假设能够就是yes,假设都不行就是no.注意构造时候的推断,因为 ...

  7. hdu 5869 区间不同GCD个数(树状数组)

    Different GCD Subarray Query Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K ( ...

  8. hdu 5656 CA Loves GCD(n个任选k个的最大公约数和)

    CA Loves GCD  Accepts: 64  Submissions: 535  Time Limit: 6000/3000 MS (Java/Others)  Memory Limit: 2 ...

  9. Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论

    Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论 题意 给你一段数,然后小明去猜某一区间内的gcd,这里不一定是准确值,如果在这个区间内改变 ...

随机推荐

  1. 深入理解javascript函数系列第三篇

    前面的话 函数是javascript中特殊的对象,可以拥有属性和方法,就像普通的对象拥有属性和方法一样.甚至可以用Function()构造函数来创建新的函数对象.本文是深入理解javascript函数 ...

  2. hdu dp 1257 最小拦截系统

    最少拦截系统 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  3. hdu 4918

    第一道树的点分治. 感谢: http://blog.csdn.net/u013368721/article/details/40887575 首先,找出原图的重心(最大子树大小最小的点(如果作为根)) ...

  4. bzoj 1458: 士兵占领 -- 最大流

    1458: 士兵占领 Time Limit: 10 Sec  Memory Limit: 64 MB Description 有一个M * N的棋盘,有的格子是障碍.现在你要选择一些格子来放置一些士兵 ...

  5. FIS构建工具学习(一)

    一.FIS是什么 在做项目的时候,用到部门内部前端人员开发的fiskit构建工具,经过这次项目基本把它的配置弄清楚了,fiskit构建工具是基于FIS的,所以自己也准备学习FIS,以便更好的理解. 后 ...

  6. 实战-130W表增加字段耗时

    工作需要对130W的表增加字段,因为是操作线上数据库,所以提前在本地调查下耗时. 首先建表: CREATE TABLE `alter_cloumn_test` ( `id` int(11) unsig ...

  7. 前端UED网站汇总

    爱词霸UED团队 MED | 营销展现研究专家 携程UED-携程旅行前端开发团队 支付宝前端开发车间 Taobao UED Team: 淘宝网用户体验团队博客,有关用户体验设计和研究的经验分享. - ...

  8. 几种OutOfMemoryError

    JAVA虚拟机OutOfMemoryError主要包括以下四类:java.lang.OutOfMemoryError: Java heap spacejava.lang.OutOfMemoryErro ...

  9. 2038: [2009国家集训队]小Z的袜子(hose) (莫队算法)

    题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=2038 专题练习: http://acm.hust.edu.cn/vjudge/conte ...

  10. Microcontroller measures resistance without an ADC

    Sensors automate most of the processes in industry. Most of these sensors, such as those for ammonia ...