2 条题解

  • 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;
       }
      
      • 1

      信息

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