HDOJ-4002/(大连网赛1002)- Find the maximum 数论

2024-03-20 03:32

本文主要是介绍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 数论的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/828156

相关文章

数论入门整理(updating)

一、gcd lcm 基础中的基础,一般用来处理计算第一步什么的,分数化简之类。 LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; } <pre name="code" class="cpp">LL lcm(LL a, LL b){LL c = gcd(a, b);return a / c * b;} 例题:

数论ZOJ 2562

题意:给定一个数N,求小于等于N的所有数当中,约数最多的一个数,如果存在多个这样的数,输出其中最大的一个。 分析:反素数定义:对于任何正整数x,其约数的个数记做g(x).例如g(1)=1,g(6)=4.如果某个正整数x满足:对于任意i(0<i<x),都有g(i)<g(x),则称x为反素数。 性质一:一个反素数的质因子必然是从2开始连续的质数。 性质二:p=2^t1*3^t2*5^t3*7

POJ2247数论

p = 2^a*3^b*5^c*7^d 求形如上式的第n小的数。 import java.io.BufferedReader;import java.io.InputStream;import java.io.InputStreamReader;import java.io.PrintWriter;import java.math.BigInteger;import java.u

CSP-J基础之数学基础 初等数论 一篇搞懂(一)

文章目录 前言声明初等数论是什么初等数论历史1. **古代时期**2. **中世纪时期**3. **文艺复兴与近代**4. **现代时期** 整数的整除性约数什么样的整数除什么样的整数才能得到整数?条件:举例说明:一般化: 判断两个数能否被整除 因数与倍数质数与复合数使用开根号法判定质数哥德巴赫猜想最大公因数与辗转相除法计算最大公因数的常用方法:举几个例子:例子 1: 计算 12 和 18

CSP-J基础之数学基础 初等数论 一篇搞懂(二)

文章目录 前言算术基本定理简介什么是质数?举个简单例子:重要的结论:算术基本定理公式解释:举例: 算术基本定理的求法如何找出质因数:举个简单的例子: 重要的步骤:C++实现 同余举个例子:同余的性质简介1. 同余的自反性2. 同余的对称性3. 同余的传递性4. 同余的加法性质5. 同余的乘法性质 推论 总结 前言 在计算机科学和数学中,初等数论是一个重要的基础领域,涉及到整数

nyoj 1002 Trucking

同样一道改编题。 只要把题意理解了好。 简单的二分加最短路。 只要二分高度, 然后求最短路,输出满足题意的即可。 代码如下: (最短路用spfa 时间效率高) #include <iostream>#include <cstdio>#include <cstring>#include <ctime>#include <queue>using namespace st

MongoDB学习—(6)MongoDB的find查询比较符

首先,先通过以下函数向BookList集合中插入10000条数据 function insertN(obj,n){var i=0;while(i<n){obj.insert({id:i,name:"bookNumber"+i,publishTime:i+2000})i++;}}var BookList=db.getCollection("BookList")调用函数,这样,BookList

【NodeJS】Error: Cannot find module 'ms'

转载自:http://blog.csdn.net/echo_ae/article/details/75097004 问题: Error: Cannot find module 'ms'at Function.Module._resolveFilename (module.js:469:15)at Function.Module._load (module.js:417:25)at Module

leetcode#628. Maximum Product of Three Numbers

题目 Given an integer array, find three numbers whose product is maximum and output the maximum product. Example 1: Input: [1,2,3]Output: 6 Example 2: Input: [1,2,3,4]Output: 24 Note: The lengt

leetCode#448. Find All Numbers Disappeared in an Array

Description Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements of [1, n] inclusive that do not appear in this