UVa 11728 Alternate Task

Posted 大四开始ACM

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 \'\\n\'

#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;
    }
}

  

以上是关于UVa 11728 Alternate Task的主要内容,如果未能解决你的问题,请参考以下文章

UVa新汉诺塔问题(A Different Task,Uva 10795)

UVa10795 A Different Task (新汉诺塔问题)

UVA11987--Almost Union-Find

Uva10054 The Necklace

RabbitMQ笔记十七: Alternate Exchange

细说alternate三两事「精修版」