`
vcdemon
  • 浏览: 19551 次
社区版块
存档分类
最新评论
  • djx410249: 简单的自己想了几个数字测试了下,发现这个数会在经过几次跳动之后 ...
    3n+1
  • I白I: 怎么回事,好多字都卡在外面了 不显示。。。还要查看源代码看内容 ...
    3n+1

F(X)

    博客分类:
  • java
阅读更多

F(X)

题目详情:

我们定义 F(x)是满足 x  mod(a*b) == 0这样的a,b的组数。现在给你一个n,你需要求出 F(n)

输入格式:

多组数据,每组第一行有一个整数n, 0 < n <= 10^11。

输出格式:

每组输出一行,满足条件的(a,b)对数

 

 

 

答题说明:

输入样例

1

2

3

4

输出样例:

1

3

3

6

解释

第一组: (1,1)

第二组:  (1,1) (1,2) (2, 1)

第三组:  (1,1) (1,3) (3,1)

第四组:   (1,1) (1,2) (1, 4) (2, 1) (2,2) (4,1)

 

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class TestFive {
    public static Integer Test(long n) {
        if (n == 1) {
            return 1;
        }
        return PrintPrimeFactors(n) * 3;
    }

    public static Integer PrintPrimeFactors(long n) {
        Integer count0 = 0;
        HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
        ArrayList<Integer> arrayList = new ArrayList<Integer>();
        for (int i = 2; i <= n; i++) {
            while (n % i == 0) {
                if (!arrayList.contains(i)) {
                    arrayList.add(i);
                }
                if (map.containsKey(i)) {
                    Integer count = map.get(i);
                    count++;
                    map.remove(i);
                    map.put(i, count);
                } else {
                    map.put(i, 1);
                }
                n = n / i;
            }
        }

        for (int i = 0; i < map.size(); i++) {
            count0 = CombineArray(map.get(arrayList.get(i)), count0);
        }
        return count0;
    }

    public static Integer CombineArray(Integer m, Integer n) {
        return (m + n + m * n);
    }

    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        while (cin.hasNext()) {
            long n = cin.nextLong();
            System.out.println(Test(n));
        }
        cin.close();
    }
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics