zoukankan      html  css  js  c++  java
  • 我是好人 (数学推论)

    我是好人

    Description

    众所周知,我是好人!

    所以不会出太难的题,题意很简单 给你两个数n和m,问你有多少对正整数对最大公约数是n,最小公倍数是m

    最后友情提供解题代码(我真是太好人了)

    void solve()

    {

       long long n, m;

       scanf("%lld%lld", &n, &m);

       int ans = 0;

       for (long long i = 1; i <= m; i++)

       {

          for (long long j = i; j <= m; j++)

          {

               if (gcd(i, j) == n && lcm(i, j) == m) ans++;

          }

       }

       printf("%d ", ans);

    }

    祝大家AC愉快!最好AK,送某扬兑现诺言^_^

    Input

    输入第1行是一个整数T,表示共T组数据。 接下来是T组数据,每组数据占1行,每一行有2个整数n,m(1 <= n, m <= 10000000000),两个数由一个空格隔开。

    Output

    结果输出T行,对应T组数据。(T<=100)  每行输出这样的正整数对有多少对(看我多好人,不用你们输出所有整数对)

    Sample Input

    3
    1  1
    7  10086
    4  16

    Sample Output

    1
    0
    1

    HINT

     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<math.h>
     4 typedef long long ll ;
     5 int T ;
     6 ll n , m ;
     7 
     8 ll gcd (ll a , ll b)
     9 {
    10     return b ? gcd (b , a % b) : a ;
    11 }
    12 
    13 int main ()
    14 {
    15 
    16     scanf ("%d" , &T ) ;
    17     while (T--) {
    18         scanf ("%lld%lld" , &n , &m ) ;
    19         ll ans = 0 ;
    20         if ( m % n ) {
    21             printf ("0
    ") ;
    22             continue ;
    23         }
    24         ll t = m / n ;
    25         for (ll i = 1 ; i * i <= t ; i++) { 
    26             if (t % i == 0) {
    27                 ll j = t / i ;
    28                 if (gcd (i , j) == 1) {
    29                     ans ++ ;
    30                 }
    31             }
    32         }
    33         printf ("%lld
    " , ans ) ;
    34     }
    35     return 0 ;
    36 }
    View Code


    广东oj不能用

    #ifdef judge_online

      freopen ("a.txt" , "r", stdin) ;

    #ifdef

    不能装逼了。0rz

  • 相关阅读:
    双主双写、只备份某些表且要在建表ID自增
    我的系统资源呢?php-fpm你知道吗?
    apache常用的两种工作模式 prefork和worker
    Binlog的三种模式
    Tomcat
    JVM初识、调优
    httpclient 3.1跳过https请求SSL的验证
    POM报错Failure to transfer org.apache.maven.plugins:maven-resources-plugin:pom:2.6 from
    eclipse快捷键,移动和复制一段代码
    org.codehaus.jettison.json.JSONObject使用方法
  • 原文地址:https://www.cnblogs.com/get-an-AC-everyday/p/4345088.html
Copyright © 2011-2022 走看看