杭电ACM 1017 1018 1019

1017 .A Mathematical Curiosity

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.

http://acm.hdu.edu.cn/showproblem.php?pid=1017

题目大意:给定m,n,且a,b满足条件0 < a < b < n,求使(a^2+b^2 +m)/(ab) 为整数的a,b的对数。

import java.util.Scanner;

public class Main{

    public static void main(String args[]){
        Scanner s=new Scanner(System.in);
        int T=s.nextInt();
        for(int i=0;i<T;i++){
            int c=0;
            while(true){
                int n=s.nextInt();
                int m=s.nextInt();
                c++;
                if(n==0&&m==0)
                    break;
                int count=0;
                for(int a=1;a<n;a++){
                    for(int b=a+1;b<n;b++){
                        if((m+a*a)%b==0&&(m+b*b)%a==0){
                            if(((a*a+m)/b+b)%a==0){
                                count++;
                            }
                        }
                    }
                }
                System.out.println("Case "+c+": "+count);
            }
            if(i<T-1)
                System.out.println();
        }
    }
}

1018 .Big Number

Problem Description
In many applications very large integers numbers are required. Some of these applications are using keys for secure transmission of data, encryption, etc. In this problem you are given a number, you have to determine the number of digits in the factorial of the number.

Input
Input consists of several lines of integer numbers. The first line contains an integer n, which is the number of cases to be tested, followed by n lines, one integer 1 ≤ n ≤ 107 on each line.

Output
The output contains the number of digits in the factorial of the integers appearing in the input.

http://acm.hdu.edu.cn/showproblem.php?pid=1018

题目大意:求n的阶乘的位数。

分析:不要用java中的BigInteger去计算结果再输出位数,虽然BigInteger很方便,但是在这里也得不出结果的,用Strling公式。
[log10(n)]+1就是n的位数。

import java.util.Scanner;

public class Main {

    public static void main(String args[]){
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();
        for(int i=0;i<n;i++){
            int d=s.nextInt();
            double bt=((0.5*(Math.log((2*3.14159265*d))))+
                    d*Math.log(d/Math.E))/Math.log(10);
            int c=(int)bt+1;
            System.out.println(c);
        }
    }
}

1019 .Least Common Multiple

Problem Description
The least common multiple (LCM) of a set of positive integers is the smallest positive integer which is divisible by all the numbers in the set. For example, the LCM of 5, 7 and 15 is 105.

Input
Input will consist of multiple problem instances. The first line of the input will contain a single integer indicating the number of problem instances. Each instance will consist of a single line of the form m n1 n2 n3 … nm where m is the number of integers in the set and n1 … nm are the integers. All integers will be positive and lie within the range of a 32-bit integer.

Output
For each problem instance, output a single line containing the corresponding LCM. All results will lie in the range of a 32-bit integer.

http://acm.hdu.edu.cn/showproblem.php?pid=1019

题目大意:求大数的最小公倍数。

分析:直接用BigInteger 类,这种类型的题目对于java编程来说简直不需要任何思考。

import java.math.BigInteger;
import java.util.Scanner;

public class Main {

    public static void main(String args[]){
        Scanner s=new Scanner(System.in);
        int N=s.nextInt();
        for(int i=0;i<N;i++){
            int n=s.nextInt();
            BigInteger lcm=new BigInteger("1");
            for(int j=0;j<n;j++){
                BigInteger a=s.nextBigInteger();
                lcm=(a.multiply(lcm)).divide(a.gcd(lcm));
            }
            System.out.println(lcm.toString());
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值