zoukankan      html  css  js  c++  java
  • hd acm1017

    Problem Description
    Given two integers n and m, count the number of pairs of integers (a,b) such that 0 < a < b < n and (a^2+b^2 +m)/(ab) is an integer.

    This problem contains multiple test cases!

    The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.

    The output format consists of N output blocks. There is a blank line between output blocks.
     

    Input

    You will be given a number of cases in the input. Each case is specified by a line containing the integers n and m. The end of input is indicated by a case in which n = m = 0. You may assume that 0 < n <= 100.
     

    Output

    For each case, print the case number as well as the number of pairs (a,b) satisfying the given property. Print the output for each case on one line in the format as shown below.
     
    Sample Input
    1
     
    10 1
    20 3
    30 4
    0 0
     

    Sample Output

    Case 1: 2
    Case 2: 4
    Case 3: 5
     
    Sample Way
     

    #include <stdio.h>
    int main()
    {
      int n,m,N,a,b,i,count,j;
      scanf("%d",&N);
      for(i=0;i<N;i++)
      {
      j=0;
        while(scanf("%d%d",&n,&m)!=EOF&&(n!=0||m!=0))
        {
          count=0;
        for(a=1;a<n;a++){
          for(b=a+1;b<n;b++){
            if((a*a+b*b+m)%(a*b)==0) count++;
          }
        }
        printf("Case %d: %d ",++j,count);
        }
      if(i<N-1) printf(" ");
      }
    return 0;
    }

    析:

    非常狗血的一道题,简单的数学问题,给出一个区间(m,n),求在这个区间之内有多少对满足0<a<b<n并且 (a^2+b^2 +m)/(ab)是整数这个条件的a,b。

    下面是这道题的槽点——输出格式,我费了半天劲,终于搞明白了,要求你输入一个整数N,在这之后是一个空行,接下来有N个输入块,每个输入块都以0 0的输入为结束标志,然后每个输入块中你要输入m和n,注意在你输入0 0之前,这个输入块是不会结束的。所以Sample Input的意思是只有一个输入块,然后0 0的时候就结束了,结束的时候没有空行,也就是暗示你程序最后一个输入块结束时不需要空行,之前的输入块之间都有空行ToT。

  • 相关阅读:
    行转列(FOR XML PATH)
    非聚集索引的注意事项
    避免JS全局变量冲突
    如何做个好员工?
    SQL Server 执行计划中的扫描方式举例说明
    SqlServer with递归查询的使用
    Excel插件类库的设计思路
    使用log4javascript记录日志
    布局
    Image控件的简单使用示例1
  • 原文地址:https://www.cnblogs.com/clljs/p/7423832.html
Copyright © 2011-2022 走看看