题意:求1-n内最大的x/phi(x)
通式:φ(x)=x*(1-1/p1)*(1-1/p2)*(1-1/p3)*(1-1/p4)…..(1-1/pn),其中p1, p2……pn为x的所有质因数,x是不为0的整数。φ(1)=1(唯一和1互质的数就是1本身)。
因此含质因数最多的即为所求,打表求出前n个积,之后找到比自己小的最大积
大数打表
2015-07-27:到此一游
1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath> 6 #include<queue> 7 using namespace std; 8 int n,m,t; 9 char c[][500]= 10 { 11 "2", 12 "6", 13 "30", 14 "210", 15 "2310", 16 "30030", 17 "510510", 18 "9699690", 19 "223092870", 20 "6469693230", 21 "200560490130", 22 "7420738134810", 23 "304250263527210", 24 "13082761331670030", 25 "614889782588491410", 26 "32589158477190044730", 27 "1922760350154212639070", 28 "117288381359406970983270", 29 "7858321551080267055879090", 30 "557940830126698960967415390", 31 "40729680599249024150621323470", 32 "3217644767340672907899084554130", 33 "267064515689275851355624017992790", 34 "23768741896345550770650537601358310", 35 "2305567963945518424753102147331756070", 36 "232862364358497360900063316880507363070", 37 "23984823528925228172706521638692258396210", 38 "2566376117594999414479597815340071648394470", 39 "279734996817854936178276161872067809674997230", 40 "31610054640417607788145206291543662493274686990", 41 "4014476939333036189094441199026045136645885247730", 42 "525896479052627740771371797072411912900610967452630", 43 "72047817630210000485677936198920432067383702541010310", 44 "10014646650599190067509233131649940057366334653200433090", 45 "1492182350939279320058875736615841068547583863326864530410", 46 "225319534991831177328890236228992001350685163362356544091910", 47 "35375166993717494840635767087951744212057570647889977422429870", 48 "5766152219975951659023630035336134306565384015606066319856068810", 49 "962947420735983927056946215901134429196419130606213075415963491270", 50 "166589903787325219380851695350896256250980509594874862046961683989710", 51 "29819592777931214269172453467810429868925511217482600306406141434158090", 52 "5397346292805549782720214077673687806275517530364350655459511599582614290", 53 "1030893141925860008499560888835674370998623848299590975192766715520279329390", 54 "198962376391690981640415251545285153602734402721821058212203976095413910572270", 55 "39195588149163123383161804554421175259738677336198748467804183290796540382737190", 56 "7799922041683461553249199106329813876687996789903550945093032474868511536164700810", 57 "1645783550795210387735581011435590727981167322669649249414629852197255934130751870910", 58 "367009731827331916465034565550136732339800312955331782619462457039988073311157667212930", 59 "83311209124804345037562846379881038241134671040860314654617977748077292641632790457335110", 60 "19078266889580195013601891820992757757219839668357012055907516904309700014933909014729740190", 61 "4445236185272185438169240794291312557432222642727183809026451438704160103479600800432029464270", 62 "1062411448280052319722448549835623701226301211611796930357321893850294264731624591303255041960530", 63 "256041159035492609053110100510385311995538591998443060216114576417920917800321526504084465112487730", 64 "64266330917908644872330635228106713310880186591609208114244758680898150367880703152525200743234420230" 65 }; 66 int main() 67 { 68 int i,j,k; 69 //freopen("1.in","r",stdin); 70 scanf("%d",&t); 71 char s[110]; 72 while(t--) 73 { 74 scanf("%s",s); 75 int len1=strlen(s); 76 for(i=1;i<60;i++) 77 { 78 int len2=strlen(c[i]); 79 if(len1>len2) continue; 80 if(len2>len1) break; 81 if(strcmp(s,c[i])<0) break; //比cc里的数小 82 } 83 printf("%s\n",c[i-1]); 84 } 85 return 0; 86 }
时间: 2024-10-07 21:31:53