zoukankan      html  css  js  c++  java
  • A Mathematical Curiosity

    Problem Description

    Given twointegers 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 aninteger.

    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 begiven a number of cases in the input. Each case is specified by a linecontaining the integers n and m. The end of input is indicated by a case inwhich n = m = 0. You may assume that 0 < n <= 100.

    Output

    For eachcase, print the case number as well as the number of pairs (a,b) satisfying thegiven property. Print the output for each case on one line in the format asshown below.

    Sample Input

    1

     

    10 1

    20 3

    30 4

    0 0停止输入,开始输出

    Sample Output

    Case 1: 2

    Case 2: 4

    Case 3: 5

    #include<iostream>
    using namespace std;
    int main()
    {
    	int a,b,m,n,N,count,Case;
    
    	cin>>N;
    
    	int i;
    	for(i=0;i<N;++i)//可以用while(N--),但是控制每个模块之间的空行要用 if(N)【N不为0时,每个模块才空行】
    	{
    		Case=1;//记录每个模块中输入的组数
    		while(cin>>n>>m&&(n||m))//特别注意只有n和m同时为0时满足才成立,所以(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)//计算(a*a+b*b+m)/(a*b)是否为整数
    					{
    						count++;//记录每组数据中使要求满足的a、b的组数
    					}
    				}
    			}
    			
    			cout<<"Case "<<Case<<": "<<count<<endl;
    			Case++;
    		}
    		if(i<N-1)
    			cout<<endl;
    	}
    	return 0;
    }


  • 相关阅读:
    Qt之等待提示框(QTimer)
    Qt之等待提示框(QPropertyAnimation)
    FormatUtil类型格式转换
    FirstLetterUtil
    文件上传下载
    file相关的操作,(md5,word转html,复制,删除等)
    SessionListener失败,退出
    JackJson的一些方法
    全局常量
    session用户账号认证(一个用户登陆,踢出前一个用户)
  • 原文地址:https://www.cnblogs.com/IT-hexiang/p/4084617.html
Copyright © 2011-2022 走看看