zoukankan      html  css  js  c++  java
  • False Ordering LightOJ

    We define b is a Divisor of a number a if a is divisible by b. So, the divisors of 12 are 1, 2, 3, 4, 6, 12. So, 12 has 6 divisors.

    Now you have to order all the integers from 1 to 1000. x will come before y if

    1)                  number of divisors of x is less than number of divisors of y

    2)                  number of divisors of x is equal to number of divisors of y and x > y.

    Input

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

    Each case contains an integer n (1 ≤ n ≤ 1000).

    Output

    For each case, print the case number and the nth number after ordering.

    Sample Input

    5

    1

    2

    3

    4

    1000

    Sample Output

    Case 1: 1

    Case 2: 997

    Case 3: 991

    Case 4: 983

    Case 5: 840

    直接分解质因子 暴力就好了。。。

    #include <iostream>
    #include <cstdio>
    #include <sstream>
    #include <cstring>
    #include <map>
    #include <set>
    #include <vector>
    #include <stack>
    #include <queue>
    #include <algorithm>
    #include <cmath>
    #define rap(a, n) for(int i=1; i<=n; i++)
    #define MOD 2018
    #define LL long long
    #define ULL unsigned long long
    #define Pair pair<int, int>
    #define mem(a, b) memset(a, b, sizeof(a))
    #define _  ios_base::sync_with_stdio(0),cin.tie(0)
    //freopen("1.txt", "r", stdin);
    using namespace std;
    const int maxn = 10010, INF = 0x7fffffff;
    int primes[maxn], vis[maxn], sum[maxn];
    int ans;
    
    struct node
    {
        int id, xi;
    }Node[maxn];
    
    
    void init()
    {
        mem(vis, 0);
        for(int i=2; i<maxn; i++)
        {
            if(vis[i]) continue;
            primes[ans++] = i;
            for(LL j = (LL)i*i; j<maxn; j+=i)
                vis[j] = 1;
        }
    }
    
    bool cmp(node a, node b)
    {
        if(a.xi == b.xi)
            return a.id > b.id;
        return a.xi < b.xi;
    }
    
    int main()
    {
        ans = 0;
        init();
        rap(1, 1000)
        {
            Node[i].id = i;
            Node[i].xi = 1;
            int temp = i;
            for(int j=0; j<ans && primes[j] * primes[j] <= temp; j++)
            {
                int cnt2 = 0;
                while(temp % primes[j] == 0)
                {
                    temp /= primes[j];
                    cnt2++;
                }
                if(cnt2 > 0)
                    Node[i].xi *= (cnt2+1);
            }
            if(temp > 1)
                Node[i].xi *= 2;
        }
        sort(Node+1, Node+1+1000, cmp);
        int T, kase = 0;
        cin>> T;
        while(T--)
        {
            int n;
            cin>> n;
            printf("Case %d: %d
    ",++kase, Node[n].id);
        }
    
        return 0;
    }
    自己选择的路,跪着也要走完。朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。
  • 相关阅读:
    oracle基本语句
    SVM入门(六)线性分类器的求解——问题的转化,直观角度
    深入浅出KMeans算法
    SVM入门(三)线性分类器Part 2
    SVM入门(一)SVM的八股简介
    Hadoop源代码分析(五)
    用HTML5 Audio API开发游戏音乐
    Hadoop源代码分析(六)
    SVM入门(四)线性分类器的求解——问题的描述Part1
    SVM入门(二)线性分类器Part 1
  • 原文地址:https://www.cnblogs.com/WTSRUVF/p/9349741.html
Copyright © 2011-2022 走看看