ZOJ 2562
来源:互联网 发布:调查问卷 代码java 编辑:程序博客网 时间:2024/06/06 05:48
想了半天 想不到什么正解、、随便搞下、、竟然不科学的没超时的过了、、
我用个map记录、、对于从第i个素数开始 能构成不小于n的数,最大divisor有多少,并且最小这个数十多少、、
然后枚举记忆化下、、、没超时 我都觉得不科学了
#include <cstdio>#include <cstring>#include <algorithm>#include <map>#include <utility>using namespace std;typedef long long LL;map< pair <LL, LL >, pair<LL , LL> > mp;LL n;LL prime[50010], is[50010];void getprime(){int cnt = 0;for(int i = 2; i <= 50000; i++){if( !is[i] ){prime[cnt++]=i;for(int j = i; j <= 50000; j += i)is[j]=1;}}}LL pow(LL x, LL y){LL tmp = 1;while(y){if(y & 1) tmp = tmp * x;x = x * x;y >>= 1;}return tmp;}LL dfs(LL i, LL n){if( mp.count(make_pair(i, n)) ) return mp[ make_pair(i, n) ].first;if(prime[i] > n){mp[ make_pair(i, n) ].first = 1;mp[ make_pair(i, n) ].second = 1;return 1;}LL tmp = prime[i] , cnt = 0, ans = 0;while( tmp <= n ){cnt++;if(ans < (cnt + 1) * dfs(i+1, n / tmp)){mp[ make_pair(i, n) ].second = tmp * mp[ make_pair(i+1, n / tmp) ].second;ans = (cnt + 1) * mp[ make_pair(i+1, n / tmp) ].first;}else {if( ans == (cnt + 1) * mp[ make_pair(i+1, n / tmp) ].first)if(mp[ make_pair(i, n) ].second > tmp * mp[ make_pair(i+1, n / tmp)].second)mp[ make_pair(i, n) ].second = tmp * mp[ make_pair(i+1, n / tmp)].second;}tmp *= prime[i];}return mp[ make_pair(i,n) ].first = ans;}int main(){getprime();mp.clear();while(~scanf("%lld",&n)){dfs(0, n);printf("%lld\n", mp[ make_pair(0,n)].second);}return 0;}
- zoj 2562
- ZOJ 2562
- zoj 2562(反素数)
- zoj 2562 More Divisors
- ZOJ 2562 数论+搜索
- ZOJ 2562 反素数
- Zoj 2562 More Divisors
- zoj 2562 More Divisors
- zoj 2562 More Divisors
- 数论ZOJ 2562
- 【ZOJ 2562】 More Divisors
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- jbpm学习笔记(四)--请假流程的设计(1)
- /etc/resolv.conf 的更改在重启后丢失的解决办法
- 编程之美——寻找最近点对
- 常用SQL基础
- 简单 dtd 实例编写
- ZOJ 2562
- 制做jffs2文件系统
- 你可能不知道的Shell
- OGNL技术讲解
- JSP页面常用总结1
- ZOJ 1576(稳定婚姻系统-重名)
- Processing Bitmaps Off the UI Thread
- AddressBook.Framework应用之ABAddressBookRef,ABRecordRef,ABMutableMultiValueRef,ABMultiValueRef
- java生成二维码