标签:
Accepted
|
79MS
|
1400K
|
2321Byte
|
2015-01-25 13:14:25.0
|
题目描述
输入
输入的第1行有两个正整数a和b。
输出
若找到的a和b之间约数个数最多的数是x,则输出div(x)。
样例输入
1 36
样例输出
9
题目来源
算法设计与实验题解
先转一发大仙的题解:
http://blog.csdn.net/u012968092/article/details/41975317
我的优化:稍微改了下搜索顺序,因为新增加一种素因子在大部分情况下,比新增加当前已有的一个素因子来的收益大~
1 #include<iostream> 2 #include<cstring> 3 #include<cstdlib> 4 #include<cstdio> 5 #include<algorithm> 6 #include<cmath> 7 #include<queue> 8 #include<map> 9 #include<set> 10 #include<stack> 11 #include<string> 12 13 #define N 100005 14 #define M 105 15 #define mod 1000000007 16 //#define p 10000007 17 #define mod2 1000000000 18 #define ll long long 19 #define LL long long 20 #define eps 1e-6 21 #define inf 1000000 22 #define maxi(a,b) (a)>(b)? (a) : (b) 23 #define mini(a,b) (a)<(b)? (a) : (b) 24 25 using namespace std; 26 27 ll a,b; 28 ll ma; 29 int f[N]; 30 ll p[N]; 31 ll ccnt; 32 33 void ini1() 34 { 35 memset(f,0,sizeof(f)); 36 ll i,j; 37 ccnt=0; 38 f[0]=f[1]=1; 39 for(i=2;i<=N-5;i++){ 40 if(f[i]==1) continue; 41 for(j=2*i;j<=N-5;j+=i){ 42 f[j]=1; 43 } 44 } 45 for(i=2;i<=N-5;i++){ 46 if(f[i]==0){ 47 p[ccnt]=i;ccnt++; 48 } 49 } 50 // printf(" cnt=%d\n",cnt); 51 } 52 53 ll quickpow(ll x,ll n) 54 { 55 ll re=1; 56 while(n) 57 { 58 if( (n&1)!=0 ){ 59 re*=x; 60 } 61 n/=2; 62 x*=x; 63 } 64 return re; 65 } 66 67 void dfs(ll st,ll now,ll cnt) 68 { 69 ll i; 70 //printf(" st=%I64d p=%I64d now=%I64d cnt=%I64d ma=%I64d\n",st,p[st],now,cnt,ma); 71 if(now>b) return; 72 if(now>=a){ 73 ma=max(ma,cnt); 74 } 75 ll temp=log(b/now)/log(p[st]); 76 ll re=quickpow(2,temp); 77 // printf(" temp=%I64d re=%I64d ma=%I64d\n",temp,re,ma); 78 if(re*cnt<=ma) return; 79 if( now<a && (a-1)/now==b/now ) return; 80 ll c=0; 81 ll te=now; 82 // printf(" te=%I64d now=%I64d\n",te,now); 83 if(st>=ccnt) return; 84 for(i=0;;i++){ 85 if(te>b) break; 86 // printf(" nst=%I64d te=%I64d ncnt=%I64d\n",st+1,te,(c+1)*cnt); 87 dfs(st+1,te,(c+1)*cnt); 88 te*=p[st]; 89 c++; 90 } 91 } 92 93 void ini() 94 { 95 ma=0; 96 } 97 98 void solve() 99 { 100 if(a>b) swap(a,b); 101 if(b==1){ 102 ma=1;return; 103 } 104 ma=2; 105 dfs(0,1,1); 106 } 107 108 void out() 109 { 110 //printf("%I64d\n",ma); 111 cout<<ma<<endl; 112 } 113 114 int main() 115 { 116 ini1(); 117 //freopen("data.in","r",stdin); 118 //freopen("data.out","w",stdout); 119 //scanf("%d",&T); 120 //for(int ccnt=1;ccnt<=T;ccnt++) 121 //while(T--) 122 // while(scanf("%I64d%I64d",&a,&b)!=EOF) 123 while(cin>>a>>b) 124 { 125 ini(); 126 solve(); 127 out(); 128 } 129 return 0; 130 }
Time Limit Exceed at Test 5
|
2323Byte
|
2015-01-25 13:17:03.0
|
|||||
|
|||||||
Wrong Answer at Test 5
|
2167Byte
|
2015-01-25 12:58:23.0
|
|||||
Wrong Answer at Test 5
|
2120Byte
|
2015-01-25 12:52:13.0
|
|||||
Wrong Answer at Test 5
|
2120Byte
|
2015-01-25 12:49:17.0
|
|||||
Wrong Answer at Test 5
|
2136Byte
|
2015-01-25 12:44:20.0
|
|||||
Wrong Answer at Test 5
|
2137Byte
|
2015-01-25 12:43:30.0
|
|||||
Wrong Answer at Test 5
|
2140Byte
|
2015-01-25 12:42:43.0
|
|||||
Wrong Answer at Test 5
|
2140Byte
|
2015-01-25 12:39:31.0
|
|||||
Runtime Error at Test 7
(STACK_OVERFLOW) |
2115Byte
|
2015-01-25 12:38:30.0
|
|||||
Accepted
|
947MS
|
712K
|
2818Byte
|
2015-01-23 22:26:01.0
|
|||
Time Limit Exceed at Test 3
|
2825Byte
|
2015-01-23 22:25:01.0
|
|||||
Accepted
|
970MS
|
712K
|
2812Byte
|
2015-01-23 21:20:34.0
|
|||
2844Byte
|
2015-01-23 21:19:14.0
|
||||||
Time Limit Exceed at Test 3
|
2173Byte
|
2015-01-23 21:17:06.0
|
|||||
Wrong Answer at Test 3
|
1830Byte
|
2015-01-23 21:02:14.0
|
|||||
Wrong Answer at Test 3
|
1806Byte
|
2015-01-23 20:58:55.0
|
|||||
Wrong Answer at Test 3
|
1804Byte
|
2015-01-23 20:57:37.0
|
|||||
Runtime Error at Test 3
(ACCESS_VIOLATION) |
1795Byte
|
2015-01-23 20:57:00.0
|
标签:
原文地址:http://www.cnblogs.com/njczy2010/p/4248113.html