zoukankan      html  css  js  c++  java
  • [LightOJ1370]Bi-shoe and Phi-shoe

    A - Bi-shoe and Phi-shoe
    Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu
     

    Description

     

    Bamboo Pole-vault is a massively popular sport in Xzhiland. And Master Phi-shoe is a very popular coach for his success. He needs some bamboos for his students, so he asked his assistant Bi-Shoe to go to the market and buy them. Plenty of Bamboos of all possible integer lengths (yes!) are available in the market. According to Xzhila tradition,

    Score of a bamboo = Φ (bamboo's length)

    (Xzhilans are really fond of number theory). For your information, Φ (n) = numbers less than n which are relatively prime (having no common divisor other than 1) to n. So, score of a bamboo of length 9 is 6 as 1, 2, 4, 5, 7, 8 are relatively prime to 9.

    The assistant Bi-shoe has to buy one bamboo for each student. As a twist, each pole-vault student of Phi-shoe has a lucky number. Bi-shoe wants to buy bamboos such that each of them gets a bamboo with a score greater than or equal to his/her lucky number. Bi-shoe wants to minimize the total amount of money spent for buying the bamboos. One unit of bamboo costs 1 Xukha. Help him.

    Input

    Input starts with an integer T (≤ 100), denoting the number of test cases.

    Each case starts with a line containing an integer n (1 ≤ n ≤ 10000) denoting the number of students of Phi-shoe. The next line contains n space separated integers denoting the lucky numbers for the students. Each lucky number will lie in the range [1, 106].

    Output

    For each case, print the case number and the minimum possible money spent for buying the bamboos. See the samples for details.

    Sample Input

    3

    5

    1 2 3 4 5

    6

    10 11 12 13 14 15

    2

    1 1

    Sample Output

    Case 1: 22 Xukha

    Case 2: 88 Xukha

    Case 3: 4 Xukha

     

     

     

     

     

    题意:求n个后面的每一个数的第一个素数并求和。

    比较笨,先打表把素数标出来再取出来,再把每一位数后面的素数打出来。就这么胡来…

     1 #include <iostream>
     2 #include <cstring>
     3 #include <cstdio>
     4 #include <cmath>
     5 
     6 using namespace std;
     7 
     8 typedef long long LL;
     9 const int maxn = 1000010;
    10 bool isprime[maxn];
    11 LL p[maxn];
    12 LL m[maxn];
    13 
    14 void printlist() {
    15     memset(isprime, true, sizeof(isprime));
    16     isprime[0] = isprime[1] = false;
    17     int pedge = int(sqrt(maxn));
    18     for(int i = 2; i <= pedge; i++) {
    19         if(isprime[i]) {
    20             int o = maxn / i;
    21             for(int j = 2; j <= o; j++) {
    22                 isprime[i*j] = false;
    23             }
    24         }
    25     }
    26 } 
    27 
    28 void init() {
    29     printlist();
    30     int k = 0;
    31     for(int i = 0; i < maxn; i++) {
    32         if(isprime[i]) {
    33             p[k++] = i;
    34         }
    35     }
    36     k = 0;
    37     for(int i = 0; i < maxn; i++) {
    38         if(i < p[k]){ 
    39             m[i] = p[k];
    40             continue;
    41         }
    42         m[i] = p[++k];
    43     }
    44 }
    45 
    46 int main() {
    47     int T, n;
    48     init();
    49     scanf("%d", &T);
    50     for(int ii = 1; ii <= T; ii++) {
    51         scanf("%d", &n);
    52         LL ans = 0;
    53         int tmp;
    54         while(n--) {
    55             scanf("%d", &tmp);
    56             ans += m[tmp];
    57         }
    58         printf("Case %d: %lld Xukha
    ", ii, ans);
    59     }
    60 }
  • 相关阅读:
    EF性能优化-有人说EF性能低,我想说:EF确实不如ADO.NET
    MiniProfiler工具介绍(监控EF生成的SQL语句)--EF,迷你监控器,哈哈哈
    C# 数据库并发的解决方案(通用版、EF版)
    锁、C#中Monitor和Lock以及区别
    LINQ 如何动态创建 Where 子查询
    C# Npoi 实现Excel与数据库相互导入
    MVC ActionResult派生类关系图
    如何构造树状 JSON 数据 JSON-Tree
    如何构造分层次的 Json 数据
    如何使用 GroupBy 计数-Count()
  • 原文地址:https://www.cnblogs.com/kirai/p/4743121.html
Copyright © 2011-2022 走看看