本文主要是介绍HDOJ-4002/(大连网赛1002)- Find the maximum 数论,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
打表过的,顺便贴一下,嘻嘻....
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
using namespace std;
const int maxn = 110;
char n[maxn];#define MAXN 60
string low[MAXN];
int e[MAXN];
void set() {low[0] += "2",low[1] += "6",low[2] += "30",low[3] += "210",low[4] += "2310",low[5] += "30030",low[6] += "510510",low[7] += "9699690",low[8] += "223092870",low[9] += "6469693230",low[10] += "200560490130",low[11] += "7420738134810",low[12] += "304250263527210",low[13] += "13082761331670030",low[14] += "614889782588491410",low[15] += "32589158477190044730",low[16] += "1922760350154212639070",low[17] += "117288381359406970983270",low[18] += "7858321551080267055879090",low[19] += "557940830126698960967415390",low[20] += "40729680599249024150621323470",low[21] += "3217644767340672907899084554130",low[22] += "267064515689275851355624017992790",low[23] += "23768741896345550770650537601358310",low[24] += "2305567963945518424753102147331756070",low[25] += "232862364358497360900063316880507363070",low[26] += "23984823528925228172706521638692258396210",low[27] += "2566376117594999414479597815340071648394470",low[28] += "279734996817854936178276161872067809674997230",low[29] += "31610054640417607788145206291543662493274686990",low[30] += "4014476939333036189094441199026045136645885247730",low[31] += "525896479052627740771371797072411912900610967452630",low[32] += "72047817630210000485677936198920432067383702541010310",low[33] += "10014646650599190067509233131649940057366334653200433090",low[34] += "1492182350939279320058875736615841068547583863326864530410",low[35] += "225319534991831177328890236228992001350685163362356544091910",low[36] += "35375166993717494840635767087951744212057570647889977422429870",low[37] += "5766152219975951659023630035336134306565384015606066319856068810",low[38] += "962947420735983927056946215901134429196419130606213075415963491270",low[39] += "166589903787325219380851695350896256250980509594874862046961683989710",low[40] += "29819592777931214269172453467810429868925511217482600306406141434158090",low[41] += "5397346292805549782720214077673687806275517530364350655459511599582614290",low[42] += "1030893141925860008499560888835674370998623848299590975192766715520279329390",low[43] += "198962376391690981640415251545285153602734402721821058212203976095413910572270",low[44] += "39195588149163123383161804554421175259738677336198748467804183290796540382737190",low[45] += "7799922041683461553249199106329813876687996789903550945093032474868511536164700810",low[46] += "1645783550795210387735581011435590727981167322669649249414629852197255934130751870910",low[47] += "367009731827331916465034565550136732339800312955331782619462457039988073311157667212930",low[48] += "83311209124804345037562846379881038241134671040860314654617977748077292641632790457335110",low[49] += "19078266889580195013601891820992757757219839668357012055907516904309700014933909014729740190",low[50] += "4445236185272185438169240794291312557432222642727183809026451438704160103479600800432029464270",low[51] += "1062411448280052319722448549835623701226301211611796930357321893850294264731624591303255041960530",low[52] += "256041159035492609053110100510385311995538591998443060216114576417920917800321526504084465112487730",low[53] += "64266330917908644872330635228106713310880186591609208114244758680898150367880703152525200743234420230",low[54] += "16516447045902521732188973253623425320896207954043566485360902980990824644545340710198976591011245999110",low[55] += "4343825573072363215565699965702960859395702691913457985649917484000586881515424606782330843435957697765930";
e[0] =1,e[1] =1,e[2] =2,e[3] =3,e[4] =4,e[5] =5,e[6] =6,e[7] =7,e[8] =9,e[9] =10,e[10] =12,e[11] =13,e[12] =15,e[13] =17,e[14] =18,e[15] =20,e[16] =22,e[17] =24,e[18] =25,e[19] =27,e[20] =29,e[21] =31,e[22] =33,e[23] =35,e[24] =37,e[25] =39,e[26] =41,e[27] =43,e[28] =45,e[29] =47,e[30] =49,e[31] =51,e[32] =53,e[33] =56,e[34] =58,e[35] =60,e[36] =62,e[37] =64,e[38] =66,e[39] =69,e[40] =71,e[41] =73,e[42] =76,e[43] =78,e[44] =80,e[45] =82,e[46] =85,e[47] =87,e[48] =89,e[49] =92,e[50] =94,e[51] =97,e[52] =99,e[53] =101,e[54] =104,e[55] =106;}/int getk()
{for(int i=0; i<=MAXN; i++){if(e[i] >= strlen(n)) //k 位数大于等于nreturn i;}
}int isbig(int k) //low[k], n
{for(int i=0; i< e[k]; i++){if(n[i] > low[k][i])return 1;else if(n[i] < low[k][i])return 0;}return -1;
}void solve()
{if(strlen(n)==1 && n[0]>='6' && n[0]<='9') {cout<<6<<endl; return; }int k = getk();if(e[k] > strlen(n)) { cout<<low[k-1]<<endl; return;}int i = k;{int flag = isbig(i);if(flag == 1){cout<<low[i]<<endl;}else if(flag == 0) //n小{cout<<low[i-1]<<endl;}else if(flag == -1){cout<<n<<endl;}}
}int main() {int t;cin>>t;set();while(t--){while(cin>>n){solve();}}
}
这篇关于HDOJ-4002/(大连网赛1002)- Find the maximum 数论的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!