题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3085

题意:求n(<=10^100)之内最大的反素数。

思路:

优化2:

int prime[]=
{
1, 2, 3, 5, 7,
11, 13, 17, 19, 23,
29, 31, 37, 41, 43,
47, 53, 59, 61, 67,
71, 73, 79, 83, 89,
97, 101,103,107,109,
113,127,131,137,139,
149,151,157,163,167,
173,179,181,191,193,
197,199,211,223,227,
229,233,239,241,251
};
int K[]=
{
1,2,2,3,3,
4,4,5,5,5,
5,5,6,6,6,
6,6,6,6,7,
7,7,7,7,7,
7,7,7,7,7,
7,7,8,8,8,
8,8,8,8,8,
8,8,8,8,8,
8,8,8,8,8,
8,8,8,8,8
};
struct BIGINT
{
int a[27]; BIGINT(){}
BIGINT(char *s)
{
clr(a,0);
int i,L=strlen(s),cur=0;
for(i=L-1;i-3>=0;i-=4)
{
a[cur]=(s[i-3]-'0')*1000+
(s[i-2]-'0')*100+
(s[i-1]-'0')*10+
(s[i]-'0');
cur++;
}
if(i<0) return;
if(i==0) a[cur]=s[0]-'0';
else if(i==1) a[cur]=10*(s[0]-'0')+(s[1]-'0');
else if(i==2) a[cur]=100*(s[0]-'0')+10*(s[1]-'0')+(s[2]-'0');
}
BIGINT(int x)
{
clr(a,0);
a[0]=x;
} inline BIGINT operator*(int x)
{
int i;
BIGINT tmp;
for(i=0;i<27;i++) tmp.a[i]=a[i]*x;
for(i=0;i<26;i++)
{
tmp.a[i+1]+=tmp.a[i]/10000;
tmp.a[i]%=10000;
}
return tmp;
} int operator<(BIGINT p)
{
int i;
for(i=26;i>=0;i--)
{
if(a[i]<p.a[i]) return 1;
if(a[i]>p.a[i]) return 0;
}
return 0;
} int operator==(BIGINT p)
{
int i;
for(i=26;i>=0;i--)
{
if(a[i]!=p.a[i]) return 0;
}
return 1;
}
int operator<=(BIGINT p)
{
return *this==p||*this<p;
} void print()
{
int cur=26;
while(cur>0&&0==a[cur]) cur--;
printf("%d",a[cur]);
cur--;
while(cur>=0) printf("%04d",a[cur--]);
puts("");
}
}; char s[111];
BIGINT n;
int Max; int cnt2; BIGINT ans;
i64 ansFac; void DFS(int dep,BIGINT cur,i64 facNum,int preMax)
{
if(facNum>ansFac||facNum==ansFac&&cur<ans)
{
ans=cur;
ansFac=facNum;
}
int i;
i64 tmp=facNum;
int Min=min(preMax,2*K[Max]-1-1);
if(dep>1) Min=min(Min,cnt2/(K[dep]-1));
for(i=1;i<=Min;i++)
{
if(dep==1) cnt2=i;
cur=cur*prime[dep];
tmp+=facNum;
if(n<cur) break;
DFS(dep+1,cur,tmp,i);
}
} int main()
{ scanf("%s",s);
n=BIGINT(s); if(n==BIGINT(1))
{
puts("1");
return 0;
}
BIGINT cur=BIGINT(1);
while(cur<=n) cur=cur*prime[++Max];
DFS(1,BIGINT(1),1,100);
ans.print();
}

BZOJ 3085: 反质数加强版SAPGAP (反素数搜索)的更多相关文章

  1. bzoj:3085: 反质数加强版SAPGAP

    Description 先解释一下SAPGAP=Super AntiPrime, Greatest AntiPrime(真不是网络流),于是你就应该知道本题是一个关于反质数(Antiprime)的问题 ...

  2. BZOJ1053 [HAOI2007]反素数 & BZOJ3085 反质数加强版SAPGAP

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

  3. 反质数(Antiprimes)

    转载http://www.cnblogs.com/tiankonguse/archive/2012/07/29/2613877.html 问题描述: 对于任何正整数x,起约数的个数记做g(x).例如g ...

  4. CNUOJ 0486 800401反质数

    难度级别:A: 运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 将正整数 x 的约数个数表示为 g(x).例如,g(1)=1,g(4)=3, g ...

  5. 反质数问题,求不大于n的最大反质数

    反质数:设f(n)表示n个约数的个数,如果对于任意x有0<x<n, f(x) < f(n),那么n就是一个反质数 我们都知道对于任意一个数n,都可以用质数乘积的形式表示出来:x = ...

  6. COJN 0486 800401反质数 呵呵呵呵呵

    800401反质数 难度级别:A: 运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 将正整数 x 的约数个数表示为 g(x).例如,g(1)=1 ...

  7. HYSBZ 1053 反质数

    input n 1<=n<=2000000000 output 不大于n的最大反质数 对于任何正整数x,其约数的个数记作g(x).例如g(1)=1.g(6)=4.如果某个正整数x满足:g( ...

  8. Android反编译(二)之反编译XML资源文件

    Android反编译(二) 之反编译XML资源文件 [目录] 1.工具 2.反编译步骤 3.重新编译APK 4.实例 5.装X技巧 6.学习总结 1.工具 1).反编译工具  apktool http ...

  9. Android反编译(一)之反编译JAVA源码

    Android反编译(一) 之反编译JAVA源码 [目录] 1.工具 2.反编译步骤 3.实例 4.装X技巧 1.工具 1).dex反编译JAR工具  dex2jar   http://code.go ...

随机推荐

  1. 下拉框分组显示optgroup

    <select> <optgroup label="语言"> <option>中文</option> <option>英 ...

  2. NOIP201205Vigenère密码

                                   NOIP201205Vigenère密码 [问题描述]   16 世纪法国外交家Blaise de Vigenère设计了一种多表密码加密 ...

  3. 创建与删除SQL约束或字段约束

    1)禁止所有表约束的SQLselect 'alter table '+name+' nocheck constraint all' from sysobjects where type='U'2)删除 ...

  4. 通过HP Loadrunner VuGen来录制安卓的应用

    作者:Richard Pal       来自:perftesting           翻译:Elaine00 通过这篇文章,我将介绍如何通过HP Loadrunner VuGen来测试一个安卓应 ...

  5. android 百度地图定位开发1

    首先注册成为百度开发者 然后进入百度开发者中心 点击LBS 跳到下一个页面 点击Android 开发 里面的基础地图 进入  点击获取密钥 进入   点击创建应用 进入     应用名称自己填 应用类 ...

  6. android 项目学习随笔二(引导页 )

    1.引导页 1.定义灰色.红色圆点的shape XML文件 2.定义布局文件,利用相对布局文件定位,利用线性布局加载灰色圆点,imageview加载红色圆点 3.android.support.v4. ...

  7. IT书籍的选择与阅读

    拍摄是一件艰苦而有趣的事情. 它需要眼睛和心灵完全融合投入, 需要耐心等待排除干扰, 需要敏捷捕捉稍纵即逝的瞬间. 但是, 非艰苦不成乐趣. 人生也应该选择一件有难度的事情来做. 做不成, 可以收获过 ...

  8. mysql开启远程访问

    1.MySql-Server 出于安全方面考虑只允许本机(localhost, 127.0.0.1)来连接访问. 这对于 Web-Server 与 MySql-Server 都在同一台服务器上的网站架 ...

  9. Android NDK 开发(三)--常见错误锦集合Log的使用【转】

    转载请注明出处:http://blog.csdn.net/allen315410/article/details/41826511  Android NDK开发经常因某些因素会出现一些意想不到的错误, ...

  10. LUA笔记之表

    表据说是LUA的核, 呵呵, 看例子吧, 看上去, 跟java的list很像, 又有点像json: a = {} -- create a table and store its reference i ...