A search for narrow and broad resonances with masses greater than 1.8TeV decaying to a pair of jets is presented. The search uses proton-proton collision data at root s = 13TeV collected at the LHC, corresponding to an integrated luminosity of 137 fb(-1). The background arising from standard model processes is predicted with the fit method used in previous publications and with a new method. The dijet invariant mass spectrum is well described by both data-driven methods, and no significant evidence for the production of new particles is observed. Model independent upper limits are reported on the production cross sections of narrow resonances, and broad resonances with widths up to 55% of the resonance mass. Limits are presented on the masses of narrow resonances from various models: string resonances, scalar diquarks, axigluons, colorons, excited quarks, color-octet scalars, W' and Z' bosons, Randall-Sundrum gravitons, and dark matter mediators. The limits on narrow resonances are improved by 200 to 800 GeV relative to those reported in previous CMS dijet resonance searches. The limits on dark matter mediators are presented as a function of the resonance mass and width, and on the associated coupling strength as a function of the mediator mass. These limits exclude at 95% confidence level a dark matter mediator with a mass of 1.8TeV and width 1% of its mass or higher, up to one with a mass of 4.8TeV and a width 45% of its mass or higher.