题目链接: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. Perl中的匹配(六)

    在Perl中,匹配的定界符如果是双斜线//,可以直接使用双斜线完成匹配操作. 如果特定条件下需要改变定界符,如改为{},[]等.需要加入m,m{},m[]等. m%^http://% 默认的模式匹配对 ...

  2. 在linux中的virtualbox无法挂载usb设备的解决方法

    方法来源于网络. 在安装完virtualbox之后,virtualbox会建立一个名为 vboxusers 的组,将你的用户名加入到该组即可. 命令参考: #usermod -a -G vboxuse ...

  3. jquery表单重置另一种方法

    页面中按钮为<a>标签时,点击取消按钮,表单内容重置,需要给form表单id="form": <a class="demo_one1" onc ...

  4. keep your work after network broken

    如下设置可以保证在网络中断后tso仍然可以继续active,并等到下一次reconnect sys1.tcpparms(tnprof7d) -- Dataset name and PDS name b ...

  5. Android扫描文件

    扫描文件及文件夹 package com.bwie.demo; import java.io.File; import java.io.FileFilter; import java.util.Arr ...

  6. startActivityForResult 页面跳转回调

    import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; import java.util. ...

  7. :first // :last

    描述: 获取匹配的第一个元素 HTML 代码: <ul> <li>list item 1</li> <li>list item 2</li> ...

  8. 【secureCRT】会话保存的路径

  9. Spring JDBC保存枚举对象含关键字报错原因之一

    报错信息: org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized S ...

  10. dom4j读写XML文件

    XML文件格式: <?xml version="1.0" encoding="UTF-8"?> <company> <employ ...