zoukankan      html  css  js  c++  java
  • HDU 4002 Find the maximum(欧拉函数)

    题目链接

    猜了一个结论,题面跟欧拉函数有关系。

     1 import java.util.*;
     2 import java.math.*;
     3 import java.text.*;
     4 import java.io.*;
     5 
     6 public class Main {
     7 
     8     public static void main(String[] args) {
     9         Scanner cin = new Scanner(System.in);
    10         int p[] = new int[1001];
    11         int prim[] = new int[1001];
    12         int i, j, num, t;
    13         BigInteger n, temp;
    14         BigInteger s[] = new BigInteger[201];
    15         num = 0;
    16         for (i = 0; i <= 1000; i++)
    17             p[i] = 0;
    18         for (i = 2; i <= 1000; i++) {
    19             if (p[i] == 0) {
    20                 prim[num++] = i;
    21                 for (j = i + i; j <= 1000; j += i) {
    22                     p[j] = 1;
    23                 }
    24             }
    25         }
    26         s[0] = BigInteger.valueOf(prim[0]);
    27         for (i = 1; i < 150; i++) {
    28             temp = BigInteger.valueOf(prim[i]);
    29             s[i] = s[i - 1].multiply(temp);
    30             
    31         }
    32         t = cin.nextInt();
    33         while (t > 0) {
    34             n = cin.nextBigInteger();
    35             for (i = 1; i < num; i++) {
    36                 if (n.compareTo(s[i]) == -1) {
    37                     break;
    38                 }
    39             }
    40             System.out.println(s[i-1]);
    41             t--;
    42         }
    43     }
    44 }
  • 相关阅读:
    POJ 3253 Fence Repair
    POJ 2431 Expedition
    NYOJ 269 VF
    NYOJ 456 邮票分你一半
    划分数问题 DP
    HDU 1253 胜利大逃亡
    NYOJ 294 Bot Trust
    NYOJ 36 最长公共子序列
    HDU 1555 How many days?
    01背包 (大数据)
  • 原文地址:https://www.cnblogs.com/naix-x/p/3409049.html
Copyright © 2011-2022 走看看