zoukankan      html  css  js  c++  java
  • 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
    
  • 相关阅读:
    匈牙利算法自主总结
    luogu P2071 座位安排
    luogu P1613 跑路
    luogu P1250 种树
    luogu P1744 采购特价商品
    网络流
    其他图论
    组合计数
    小技巧
    矩阵&&高斯消元
  • 原文地址:https://www.cnblogs.com/chaolong/p/3165180.html
Copyright © 2011-2022 走看看