3 条题解

  • 1
    @ 2024-4-11 20:47:11

    #include<bits/stdc++.h> using namespace std; int gad(int x,int y) { while(y^=x^=y^=x%=y); return x; } bool solve() { int ans=0; for(int i=1;i<=2020;i++) { for(int j=1;j<=2020;j++) { if(gad(i,j)==1) ans++; } } cout<<ans; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); solve(); return 0; }

    • 1
      @ 2024-4-8 0:04:41

      【2020年省赛B组】试题B:既约分数

      题解

      • 2481215

      简单模拟题目, 分别从1\sim2020枚举分子、分母, 然后判断当前枚举到的分子和分母的gcd是否为1, 如果为1则ans++。(ans表示答案)

      最后答案为2481215

      提交代码

      #include<bits/stdc++.h>
       using namespace std;
       signed main()
       {
           int ans = 0;
           for(int i = 1 ; i <= 2020 ; i ++){
               for(int j = 1 ; j <= 2020 ; j ++){
                   if(__gcd(i , j) == 1) ans ++ ;
               }
           }
           cout << ans << '\n';
           return 0;
       }
      
      • 0
        @ 2026-9-15 11:22:38

        Python 1.纯纯数学题,也不需要考虑时间复杂度啥的 暴力即可 2.代码如下 import math ans = 0 for i in range(1,2021): ****for j in range(1,2021): ********if math.gcd(i,j)==1: ************ans += 1 print(ans)

        • 1

        信息

        ID
        997
        时间
        1000ms
        内存
        256MiB
        难度
        2
        标签
        递交数
        80
        已通过
        47
        上传者