2 条题解
-
3njnu+19180232 LV 7 @ 2018-12-25 15:34:04
#include <stdio.h>
int f(int a,int b);
int main()
{
int x;scanf("%d",&x);
int count=0;
for(int i=2;i<x;i++)
{
int ii=i;
for(int j=ii+1;j<=x;j++)
if(f(ii,j)==-1) count++;
}
printf("%d",count);
}int f(int a,int b)
{
int t;
if(a < b)
{
t = a;a = b;b = t;
}
while(t=a%b)
{
a = b;b = t;
}
if(b == 1)
return -1;
return 0;
} -
12023-12-26 15:04:59@
#include<iostream>
using namespace std;int gcd(int a,int b)
{
if (b == 0)return a;
else return gcd(b, a % b);
}int main()
{
//(2,3), (2,5), (3,4), (3,5), (4,5), (5,6)观察知j>i
int n; cin >> n;
int cnt = 0;
for (int i = 2; i <= n; i++)
for (int j = i+1; j <= n; j++)
if (gcd(i, j) == 1 )cnt++;//3 4 4 3 3 5 5 3 重复计算cout << cnt;
return 0;
}
- 1
信息
- 难度
- 5
- 分类
- (无)
- 标签
- 递交数
- 760
- 已通过
- 277
- 通过率
- 36%
- 被复制
- 8
- 上传者