• 100c之44:求四个分数


    Table of Contents

    问题

    求四个分数且满足1/p + 1/q + 1/r + 1/s =1,其中p<=q<=r<=s.

    分析

    p的范围是[2,4], q的范围是[p,7],r的范围是[q,13].

    程序

     1:  /**
     2:   * @file   044c.c
     3:   * @author Chaolong Zhang <emacsun@163.com>
     4:   * @date   Mon Jul  1 16:33:22 2013
     5:   * 
     6:   * @brief  求四个分数且满足1/p + 1/q + 1/r + 1/s =1,其中p<=q<=r<=s.
     7:   * 
     8:   * 
     9:   */
    10:  
    11:  #include <stdio.h>
    12:  
    13:  int main(int argc, char *argv[])
    14:  {
    15:      int p,q,r,s;
    16:      int count=0;
    17:  
    18:      for (p=2; p <= 4; ++p){
    19:          for ( q= p; q <= 7; ++q){
    20:              for (r=q; r <= 13; ++r){
    21:                  if (p*q*r - p*q - p*r- q*r != 0){
    22:                      s=p*q*r/( p*q*r - p*q - p*r- q*r );
    23:                      if (0==p*q*r% ( p*q*r - p*q - p*r- q*r ) && s>=r)
    24:                      {
    25:                          printf ("%-4d 1/%-2d + 1/%-2d + 1/%-2d + 1/%-2d = 1
    ", ++count, p,q,r,s);
    26:                      }
    27:                  }
    28:              }
    29:          }
    30:      }
    31:      return 0;
    32:  }
    

    结果

    1    1/2  + 1/3  + 1/7  + 1/42 = 1
    2    1/2  + 1/3  + 1/8  + 1/24 = 1
    3    1/2  + 1/3  + 1/9  + 1/18 = 1
    4    1/2  + 1/3  + 1/10 + 1/15 = 1
    5    1/2  + 1/3  + 1/12 + 1/12 = 1
    6    1/2  + 1/4  + 1/5  + 1/20 = 1
    7    1/2  + 1/4  + 1/6  + 1/12 = 1
    8    1/2  + 1/4  + 1/8  + 1/8  = 1
    9    1/2  + 1/5  + 1/5  + 1/10 = 1
    10   1/2  + 1/6  + 1/6  + 1/6  = 1
    11   1/3  + 1/3  + 1/4  + 1/12 = 1
    12   1/3  + 1/3  + 1/6  + 1/6  = 1
    13   1/3  + 1/4  + 1/4  + 1/6  = 1
    14   1/4  + 1/4  + 1/4  + 1/4  = 1
    
  • 相关阅读:
    BZOJ 5018 [Snoi2017]英雄联盟
    BZOJ 4945 [Noi2017]游戏
    BZOJ4942 [Noi2017]整数
    BZOJ 2427 [HAOI2010]软件安装
    BZOJ 4870 [Shoi2017]组合数问题
    THINKPHP 全局404
    PHP 万能查询代码
    xml Array 相互转化
    JS 倒计时计算
    PHP 多态
  • 原文地址:https://www.cnblogs.com/chaolong/p/3165180.html
Copyright © 2020-2023  润新知