数学: HDU Co-prime
Co-prime
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 12 Accepted Submission(s) : 4
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Two integers are said to be co-prime or relatively prime if they have no common positive divisors other than 1 or, equivalently, if their greatest common divisor is 1. The number 1 is relatively prime to every integer.
Input
Output
Sample Input
2
1 10 2
3 15 5
Sample Output
Case #1: 5
Case #2: 10
Hint
Source
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#include<iostream>#include<cstring>#include<cstdio> using namespace std;typedef long long LL;const int N = 1e5+5; LL f[N],prime[N],vis[N],cnt,k;void prime_factor(){ memset(vis,0,sizeof(vis)); vis[0]=vis[1] = 1,cnt = 0; for(LL i=2;i*i<N;i++) if(!vis[i]) for(LL j=i*i;j<N;j+=i) vis[j] = 1; for(LL i=0;i<N;i++) if(!vis[i]) prime[cnt++] = i;}LL poie(LL x){ LL ret = 0,sum,tmp; for(LL i=1;i<(1LL<<k);i++){ tmp = 1,sum=0; for(LL j=0;j<k;j++) if(i&(1LL<<j)){sum++,tmp*=f[j];} if(sum&1) ret += x/tmp; else ret -= x/tmp; } return ret;} void solve_question(LL A,LL B,LL n){ LL tmp = n; k = 0 ; for(LL i=0;prime[i]*prime[i]<= tmp;i++){ if(tmp%prime[i]==0) f[k++] = prime[i]; while(tmp%prime[i]==0) tmp/=prime[i]; } if(tmp > 1) f[k++] = tmp; LL ans =B-poie(B)-A+1+poie(A-1); printf("%I64d\n",ans);}int main(){ int T,Case=0; LL A,B,n; scanf("%d",&T); prime_factor(); while(T--){ scanf("%I64d %I64d %I64d",&A,&B,&n); printf("Case #%d: ",++Case); solve_question(A,B,n); }} |
数学: HDU Co-prime的更多相关文章
- HDOJ(HDU).1016 Prime Ring Problem (DFS)
HDOJ(HDU).1016 Prime Ring Problem (DFS) [从零开始DFS(3)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...
- HDU 1016 Prime Ring Problem(经典DFS+回溯)
Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- hdu 1973 Prime Path
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1973 Prime Path Description The ministers of the cabi ...
- HDU 1016 Prime Ring Problem
在刚刚写完代码的时候才发现我以前交过这道题,可是没有过. 后来因为不理解代码,于是也就不了了之了. 可说呢,那时的我哪知道什么DFS深搜的东西啊,而且对递归的理解也很肤浅. 这道题应该算HDU 261 ...
- [HDU 1016]--Prime Ring Problem(回溯)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1016 Prime Ring Problem Time Limit: 4000/2000 MS (Jav ...
- [HDU 1973]--Prime Path(BFS,素数表)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1973 Prime Path Time Limit: 5000/1000 MS (Java/Others ...
- HDU 1016 Prime Ring Problem 题解
Problem Description A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ... ...
- HDU 1016 Prime Ring Problem(素数环问题)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1016 Prime Ring Problem Time Limit: 4000/2000 MS (Jav ...
- hdu 1016 Prime Ring Problem(DFS)
Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- hdu 1016 Prime Ring Problem(深度优先搜索)
Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
随机推荐
- CentOS7安装codeblocks
1.yum -y install epel-release 2.yum clean all && yum makecache 3.yum -y install gtk2-devel c ...
- C++ - 操作运算符
一.操作运算符 操作运算符:在C++中,编译器有能力将数据.对象和操作符共同组成表达式,解释为对全局或成员函数的调用 该全局或成员函数被称为操作符函数,程序员可以通过重定义函数操作符函数,来达到自己想 ...
- luogu P1141 01迷宫 x
P1141 01迷宫 题目描述 有一个仅由数字0与1组成的n×n格迷宫.若你位于一格0上,那么你可以移动到相邻4格中的某一格1上,同样若你位于一格1上,那么你可以移动到相邻4格中的某一格0上. 你的任 ...
- 157. [USACO Nov07] 奶牛跨栏(第三次考试大整理)
157. [USACO Nov07] 奶牛跨栏 输入文件:hurdles.in 输出文件:hurdles.out 简单对比 时间限制:1 s 内存限制:128 MB 译 by CmYkRg ...
- 【Leetcode】国王挖金矿
参考该文章 https://www.cnblogs.com/henuliulei/p/10041737.html #include <iostream> #include <cstr ...
- 详解cocos2dx 3.0的release版本在android平台的签名过程
当您的游戏准备发布前,需要编译成为release版本,命令中需要增加 -m release,编译命令如下: cocos compile -p android -m release 在编译结束后,生成x ...
- 通过ecplise导入mysql的jar包时,右键找不到build path问题
当我们执行java连接数据库程序的时候,我们需要再我们的项目里导入mysql的jar包,这时,我们需要右键->build path进行导入,但是有时候我们右键的时候并没有出现build path ...
- Python基础面试题库
Python基础面试题库 Python是一门学习曲线较为容易的编程语言,随着人工智能时代的到来,Python迎来了新一轮的高潮.目前,国内知乎.网易(游戏).腾讯(某些网站).搜狐(邮箱).金山. ...
- How do I add a simple onClick event handler to a canvas element?
How do I add a simple onClick event handler to a canvas element? When you draw to a canvas element, ...
- curl下载文件时自动创建目录
有时候需要自动创建多级目录 按照如下格式即可 curl -o d:/lei/demo/test.jpg --create-dirs http://img.7160.com/uploads/allimg ...