首页 > 试题广场 >

最简真分数

[编程题]最简真分数
  • 热度指数:17946 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
给出n个正整数,任取两个数分别作为分子和分母组成最简真分数,编程求共有几个这样的组合。

输入描述:
每组包含n(n<=600)和n个不同的整数,整数大于1且小于等于1000。


输出描述:
每行输出最简真分数组合的个数。
示例1

输入

7
3 5 7 9 11 13 15
3 
2 4 5
0

输出

17 
2
头像 用户抉择
发表于 2021-03-18 11:15:41
//将问题转换为求最大公约数 #include <stdio.h> int num(int a,int b) {     if(b==0) return a;   &n 展开全文
头像 不红红黑路同
发表于 2022-02-10 10:52:54
任何两个数,如果它们的最大公约数=1,则它们可以组成一个最简真分数。最大公约数可以用辗转相除法。 #include <iostream> #include <string> using namespace std; int GYS(int x,int y){ if( 展开全文
头像 T790T
发表于 2024-08-11 10:06:57
#include <bits/stdc++.h> using namespace std; int a[605]; int main() { int n; while(cin>>n && n!=0){ for(int i= 展开全文
头像 烤肉__
发表于 2022-01-30 00:21:14
求互质用欧几里得算法,遍历可以暴力二重循环,也可以先排序,然后第二层循环从i+1开始,因为分母必须大于分子,两种方法都可以过,而且暴力还容易写点。 #include <iostream> #include <algorithm> using namespace std; i 展开全文
头像 笑川不吃香菜
发表于 2024-03-15 14:06:54
#include <iostream> using namespace std; int GCD(int a,int b){ if(b == 0)return a; return GCD(b,a%b); } int main() { int n; whil 展开全文
头像 小花Student
发表于 2024-03-05 20:24:48
#include<iostream> bool func(int a, int b) { int min = a < b ? a : b; for(int i=2;i<=min;i++) { if(a%i == 0 && 展开全文
头像 勋谦
发表于 2024-06-26 22:02:21
#include <iostream> #include <algorithm> using namespace std; const int N = 1000; int gcdx(int a,int b){ return b ? gcdx(b,a % b):a; } 展开全文
头像 牛客892810292号
发表于 2024-08-13 14:44:56
#include <iostream> #include<bits/stdc++.h> using namespace std; int GCD(int a , int b) { if(b == 0) { return a ; } 展开全文
头像 土尔逊Torson
发表于 2023-05-08 22:31:40
//土尔逊Torson 编写于2023/5/08 #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <cstdio> using namespace std; int GCD06801(int a, 展开全文
头像 湖畔竹影12138
发表于 2024-01-12 10:59:13
#include <iostream> using namespace std; int gcd(int a,int b) { if(b==0)return a; else return gcd(b,a%b); } int main() { int n; 展开全文