zoukankan      html  css  js  c++  java
  • UVa 11728 Alternate Task

    方法:数论

    因为n <= factorsum(n) <= 1000, 可以暴力打表,求出所有n <= 1 所对应的factorsum(n), 求的时候甚至不需要O(n^0.5) 来判断因子,O(n) 判断也可以通过。

    然而如果factorsum的范围很大该如何求呢。可以推导得出

    。那么可以素数筛选预处理出素数,然后利用以上公式求解。

    code:

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <iostream>
    #include <string>
    #include <vector>
    #include <stack>
    #include <bitset>
    #include <cstdlib>
    #include <cmath>
    #include <set>
    #include <list>
    #include <deque>
    #include <map>
    #include <queue>
    #include <fstream>
    #include <cassert>
    #include <unordered_map>
    #include <cmath>
    #include <sstream>
    #include <time.h>
    #include <complex>
    #define Max(a,b) ((a)>(b)?(a):(b))
    #define Min(a,b) ((a)<(b)?(a):(b))
    #define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
    #define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
    #define DFOR(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
    #define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
    #define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
    #define FOREACH(a,b) for (auto &(a) : (b))
    #define rep(i,n) FOR(i,0,n)
    #define repn(i,n) FORN(i,1,n)
    #define drep(i,n) DFOR(i,n-1,0)
    #define drepn(i,n) DFOR(i,n,1)
    #define MAX(a,b) a = Max(a,b)
    #define MIN(a,b) a = Min(a,b)
    #define SQR(x) ((LL)(x) * (x))
    #define Reset(a,b) memset(a,b,sizeof(a))
    #define fi first
    #define se second
    #define mp make_pair
    #define pb push_back
    #define all(v) v.begin(),v.end()
    #define ALLA(arr,sz) arr,arr+sz
    #define SIZE(v) (int)v.size()
    #define SORT(v) sort(all(v))
    #define REVERSE(v) reverse(ALL(v))
    #define SORTA(arr,sz) sort(ALLA(arr,sz))
    #define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
    #define PERMUTE next_permutation
    #define TC(t) while(t--)
    #define forever for(;;)
    #define PINF 1000000000000
    #define newline '
    '
    
    #define test if(1)if(0)cerr
    using namespace std;
      using namespace std;
    typedef vector<int> vi;
    typedef vector<vi> vvi;
    typedef pair<int,int> ii;
    typedef pair<double,double> dd;
    typedef pair<char,char> cc;
    typedef vector<ii> vii;
    typedef long long ll;
    typedef unsigned long long ull;
    typedef pair<ll, ll> l4;
    const double pi = acos(-1.0);
    
    int table[1001];
    void init()
    {
        Reset(table, -1);
        for (int i = 1000; i >= 1; --i)
        {
            int ans = 0;
            for (int j = 1; j <= i; ++j)
                if (i % j == 0) ans += j;
            if (ans <= 1e3 && table[ans] == -1) table[ans] = i;
            //if (i == 101) cerr << i << " = " << ans << newline;
        }
    }
    
    int main()
    {
        init();
        int kase = 0;
        int n;
        while (cin >> n && n)
        {
            ++kase;
            cout << "Case " << kase << ": " << table[n] << newline;
        }
    }
    

      

  • 相关阅读:
    mysql查看所有触发器以及存储过程等操作集合【转】
    Hutool之Http工具类使用
    SpringCloud之Sentinel
    SpringCloud之Gateway
    com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
    [AWS DA Guru] SQS
    [AWS DA Guru] Kinesis
    [AWS DA Guru] SNS & SES
    [Typescript] Prevent Type Widening of Object Literals with TypeScript's const Assertions
    [AWS] Updating Elastic Beans Talks & RDS
  • 原文地址:https://www.cnblogs.com/skyette/p/6357324.html
Copyright © 2011-2022 走看看