NOIP 2014 D2T3 解方程 Hash大法好
题目大意:给定高次方程an*x^n...a1*x^1a0*x^0=0 求[1,m]区间内有多少个整数根 ai=10^10000,m=100W 懒得高精,考场上写的long double乱搞……30分打底50分顶天QAQ 当我终于搞定了各种非官方数据之后,我只能长跪大地,手捧鲜花,仰望上苍高喊:哈希大法好!
题目大意:给定高次方程an*x^n+...+a1*x^1+a0*x^0=0 求[1,m]区间内有多少个整数根
ai
懒得高精,考场上写的long double乱搞……30分打底50分顶天QAQ
当我终于搞定了各种非官方数据之后,我只能长跪大地,手捧鲜花,仰望上苍高喊:哈希大法好!
首先阿贝尔在200年前告诉我们 五次以上方程没有求根公式 于是我们只能枚举1~m 这个是100W
然后100W再加上1W位的精度 都不用运算直接就是跪…… 怎么办呢QAQ
哈希大法好!
令f(x)=an*x^n+...+a1*x^1+a0*x^0 易知若f(x)=0 则f(x) mod p=0
反之如果f(x) mod p=0 那么我们基本可以得出f(x)=0 p比较靠谱的时候碰撞率极低
所以我们把所有的ai都对p取模 然后对于每个解O(n)验证即可
这样是O(m*n)的 可以拿到70分 p比较靠谱的话不会挂
那么100分怎么办呢?
哈希大法好!
我们很容易就会发现f(x+p) mod p=f(x) mod p
于是我们选择一个小一些的p,预处理出0~p-1所有的f(x),然后超过p的取模即可
但是p不够大会挂啊!
于是我们多选择几个p 分别取一遍mod 只有一个值对所有的p取模之后全都0才算作解
哈希大法好!Hash Killer III至今无人AC就是在证明这个算法的正确性!哈希万岁!哈希赛高!哈希万年推!
时间复杂度O(nΣp+m) 其中Σp是选择的所有质数之和 一般选择1W左右的质数就行了
不知道为什么不管考场上拿了多少分只要回来把题切了就算做精神AC了0.0……
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #define M 110 using namespace std; typedef long long ll; const int prime[]={10007,11261,14843,19997,21893}; int n,m,stack[1001001],top; ll a[M][5],f[21893][5]; inline ll F(int x,int j) { int i; ll re=0; for(i=n;~i;i--) re=(re*x+a[i][j])%prime[j]; return re; } inline void Input(int x) { static char s[10100]; int i,j; bool flag=false; scanf("%s",s+1); for(i=1;s[i];i++) { if(s[i]=='-') flag=true; else for(j=0;j>n>>m; for(i=0;i<br> <br> </algorithm></iostream></cstring></cstdio>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Although machine learning has been around since the 1950s, as computers have become more powerful and data has exploded, there has been widespread practice in how people can use artificial intelligence to gain a competitive advantage, improve insights, and grow profits. . For different application scenarios, machine learning and differential equations have a wide range of scenarios. Everyone has already used machine learning, especially deep learning based on neural networks. ChatGPT is very popular. Do you still need to understand differential equations in depth? No matter what the answer is, it will involve a comparison between the two. So, what is the difference between machine learning and differential equations? Let’s start with the differential equations of the love model. These two equations predict the longevity of a couple’s relationship, based on psychologist John Got

Hash operation //Assign values to fields in the hash table. Returns 1 on success and 0 on failure. If the hash table does not exist, the table will be created first and then the value will be assigned. If the field already exists, the old value will be overwritten. $ret=$redis->hSet('user','realname','jetwu');//Get the value of the specified field in the hash table. If the hash table does not exist, return false. $ret=$redis->hGet('user','rea

Laravel is currently one of the most popular PHP web frameworks, providing developers with many powerful features and components, among which LaravelHash is one of them. LaravelHash is a PHP library for password hashing that can be used to keep passwords secure and make your application's user data more secure. In this article, we will learn how LaravelHash works and how to use it to hash and verify passwords. Prerequisite knowledge in learning Lara

1. What is a hashing algorithm? Both hashing and hashing come from the word hash. The former is a transliteration and the latter is a free translation. It is an algorithm that can map a binary value of any length into a fixed-length binary value. The mapped fixed-length binary value is called a hash value. An excellent hash algorithm needs to meet the following requirements: it cannot reversely deduce the original data from the hash value; it is very sensitive to the input data, and a different bit will cause the hash value to be very different; the probability of hash conflict must be Very small; the calculation process of the hash algorithm must be simple and efficient enough, even if the original data is very long, the hash value can be obtained quickly; 2. Usage scenarios of the hash algorithm 2.1 Secure encryption The more common hash encryption algorithms include MD5 ( MD5 Message-Dige

Common operations of Redis data type Hash Hash in redis is a mapping table of string type fields and values. Particularly suitable for storing objects, each hash can store more than 4 billion key-value pairs. Children's shoes who are familiar with python can think of it as a dictionary dict. The previous data type storage was k-v, and the hash storage is k-dict, and the dict will have its own k-v. 1. hset assigns values to the fields in the hash table. If the hash table does not exist, create a new hash table and perform the hset operation. If the field already exists in the hash table, the old value will be overwritten. hsetmyhashk1v1 two, h

Interacting electrons exhibit a variety of unique phenomena at different energies and temperatures. If we change their surrounding environment, they will exhibit new collective behaviors, such as spin, pairing fluctuations, etc. However, dealing with these interactions between electrons There are still many difficulties in the phenomenon. Many researchers use renormalization group (RG) to solve this problem. In the context of high-dimensional data, the emergence of machine learning (ML) technology and data-driven methods has aroused great interest among researchers in quantum physics. So far, ML ideas have been used in the interaction of electronic systems. In this article, physicists from the University of Bologna and other institutions use artificial intelligence to compress a quantum problem that has so far required 100,000 equations.

Researchers hope to use machine learning methods to automatically mine the most valuable and important intrinsic laws directly from high-dimensional nonlinear data (that is, to mine the PDE-based governing equations behind the problem) to achieve automatic knowledge discovery. Recently, research teams from Eastern Institute of Technology, University of Washington, Ruilai Intelligence, and Peking University proposed a genetic algorithm SGA-PDE based on symbolic mathematics, constructing an open candidate set that can directly mine any form of control from the data. equation. Experiments show that SGA-PDE can not only mine Burgers equation (with interaction terms), Korteweg–de Vries equation (KdV, with higher-order derivative terms), and Chafee-In

The main idea of the hashing method is to determine the storage address of the node based on its key value: taking the key value K as the independent variable, and through a certain functional relationship h(K) (called a hash function), the corresponding The function value comes
