code chef - Cool Guys题解
来源:互联网 发布:cisco 二层端口做acl 编辑:程序博客网 时间:2024/05/21 07:58
All submissions for this problem are available.
Given an integer N. Integers A and B are chosen randomly in the range [1..N]. Calculate the probability that the Greatest Common Divisor(GCD) of A and B equals to B.
Input
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. Each test case consists of a single integer N on a separate line.
Output
For each test case, output a single line containing probability as an irreducible fraction.
Given an integer N. Integers A and B are chosen randomly in the range [1..N]. Calculate the probability that the Greatest Common Divisor(GCD) of A and B equals to B.
Input
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. Each test case consists of a single integer N on a separate line.
Output
For each test case, output a single line containing probability as an irreducible fraction.
Example
Input:3123Output:1/13/45/9
Constraints
1<=T<=103
1<=N<=109
本题也是个数学题。
有两个知识点:
1 求最大公约数的算法
2 求小于等于一个数值的两数相乘的对数 - 这个又是数学公式
据说这里是数学详细解析,感兴趣的研究一下:
http://matwbn.icm.edu.pl/ksiazki/mon/mon42/mon4204.pdf
OJ系统:
http://www.codechef.com/problems/COOLGUYS/
long long mGcd(long long a, long long b){long long c = 0;while (b){c = b;b = a % b;a = c;}return c;}long long pairsOfCoolguys(long long n){long long ans = 0;long long sq = (long long)sqrt(n);for (unsigned i = 1; i <= sq; i++){ans += n/i;}ans = (ans<<1) - sq*sq;return ans;}void coolguys(){long long n = 0;int T = 0;cin>>T;while (T--){cin>>n;long long ps = pairsOfCoolguys(n);n *= n;long long d = mGcd(ps, n);cout <<(ps/d) << "/"<<(n/d)<<"\n";}}
- code chef - Cool Guys题解
- code chef - Counting Matrices题解
- code chef - Divide the Tangerine 橘子分块算法题解
- code chef - Divide the Tangerine 橘子分块算法题解
- Cool Code list
- Cool Code list
- Cool Code list
- codechef Chef and The Right Triangles 题解
- chef
- chef
- 漂亮代码列表(Cool Code list)
- 江西理工大学南昌校区cool code竞赛
- cool
- cool
- Cool!
- gitlab Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
- Chef and Prime Divisors Problem code: CHAPD (GCD问题)
- LeetCode题解:Gray Code
- ARM的优势
- 郁闷凌乱了
- NSPredicate的用法
- 我只要信任你,就会给你足够的空间去发挥与发展
- Unable to execute dex: Multiple dex files define Lcom/Player/Core/LocalModeThread;错误解决
- code chef - Cool Guys题解
- 看门狗 WDT
- Python 多线程 Threading模块
- mvc高精度类型写入数据库后,只有小数点后二位有效,其除都是0的解决办法
- CloudFoundry部署(三):BOSH部署
- kill命令
- 性能调化
- 初学spring 关于IOC与AOP 使用的设计模式
- ORACLE中的行迁移/行链接