BZOJ1053: [HAOI2007]反素数ant(爆搜)

Time Limit: 10 Sec  Memory Limit: 162 MB

Submit: 4163  Solved: 2485

[Submit][Status][Discuss]

Description

  对于任何正整数x,其约数的个数记作g(x)。例如g(1)=1、g(6)=4。如果某个正整数x满足:g(x)>g(i) 0<i<x

,则称x为反质数。例如,整数1,2,4,6等都是反质数。现在给定一个数N,你能求出不超过N的最大的反质数么

Input

  一个数N(1<=N<=2,000,000,000)。

Output

  不超过N的最大的反质数。

Sample Input

1000

Sample Output

840

HINT

Source

这题跟数论有啥关系?

好像就用到约数定理

然后一波爆搜就A了

一开始读错题了以为约数相同时求最大的wa了一发

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define LL long long 
#define int long long 
using namespace std;
const int MAXN = 1e5 + 10, INF = 1e9 + 10;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int prime[MAXN], vis[MAXN], tot = 0;
void GetPrime(int N) {
    vis[1] = 1; prime[0] = 1;
    for(int i = 2; i <= N; i++) {
        if(!vis[i]) prime[++tot] = i;
        for(int j = 1; j <= tot && prime[j] * i <= N; j++) {
            vis[i * prime[j]] = 1;
            if(!i % prime[j]) break;
        }
    }
}
int N, Ans = 0, Ansnum = 0;
void dfs(int i, LL sum, int num) {
    if(i > 16 || sum > N) return ;
    if((num > Ansnum) ||(num == Ansnum && sum < Ans)) Ans = sum, Ansnum = num;
    for(int j = 1; j <= 63 && sum * prime[i] <= N; j++) 
        dfs(i + 1, sum *= prime[i], num * (j + 1));
}
main() { 
#ifdef WIN32
    //freopen("a.in", "r", stdin);
#endif
    GetPrime(50);
    N = read();
    dfs(1, 1, 1);
    printf("%d", Ans);
    return 0;
} 

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏Golang语言社区

Knapsack problem algorithms for my real-life carry-on knapsack

I'm a nomad and live out of one carry-on bag. This means that the total weight o...

1542
来自专栏HansBug's Lab

1653: [Usaco2006 Feb]Backward Digit Sums

1653: [Usaco2006 Feb]Backward Digit Sums Time Limit: 5 Sec  Memory Limit: 64 MB ...

2734
来自专栏HansBug's Lab

3301: [USACO2011 Feb] Cow Line

3301: [USACO2011 Feb] Cow Line Time Limit: 10 Sec  Memory Limit: 128 MB Submit: ...

32010
来自专栏HansBug's Lab

1707: [Usaco2007 Nov]tanning分配防晒霜

1707: [Usaco2007 Nov]tanning分配防晒霜 Time Limit: 5 Sec  Memory Limit: 64 MB Submit:...

2997
来自专栏HansBug's Lab

1668: [Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富

1668: [Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富 Time Limit: 3 Sec  Memory Limit: ...

3364
来自专栏HansBug's Lab

1664: [Usaco2006 Open]County Fair Events 参加节日庆祝

1664: [Usaco2006 Open]County Fair Events 参加节日庆祝 Time Limit: 5 Sec  Memory Limit:...

2695
来自专栏HansBug's Lab

1644: [Usaco2007 Oct]Obstacle Course 障碍训练课

1644: [Usaco2007 Oct]Obstacle Course 障碍训练课 Time Limit: 5 Sec  Memory Limit: 64 M...

2886
来自专栏HansBug's Lab

2015: [Usaco2010 Feb]Chocolate Giving

2015: [Usaco2010 Feb]Chocolate Giving Time Limit: 10 Sec  Memory Limit: 162 MB S...

3136
来自专栏HansBug's Lab

1724: [Usaco2006 Nov]Fence Repair 切割木板

1724: [Usaco2006 Nov]Fence Repair 切割木板 Time Limit: 5 Sec  Memory Limit: 64 MB Su...

2927
来自专栏HansBug's Lab

2020: [Usaco2010 Jan]Buying Feed, II

2020: [Usaco2010 Jan]Buying Feed, II Time Limit: 3 Sec  Memory Limit: 64 MB Subm...

2817

扫码关注云+社区

领取腾讯云代金券