Math(牛客多校第三场)
Math
題意:
問(wèn)你有多少對(duì)(x,y),1<=x<=y<=n,滿足(x2 + y2)%(xy+1) == 0
題解:
這種題。。。直接打表蕪湖~
通過(guò)打表發(fā)現(xiàn):滿足情況的為(i,i * i * i),但是也有不和諧的聲音出現(xiàn):當(dāng)x=8時(shí),會(huì)出現(xiàn)兩個(gè),一個(gè)是(8,30),另一個(gè)是(8,512),后者依然滿足規(guī)律,所以前者有問(wèn)題,完美繼續(xù)找發(fā)現(xiàn)27也是,不滿足的是(27,240),再往下發(fā)現(xiàn)有(30,112),再往下看會(huì)發(fā)現(xiàn),不滿足規(guī)律的情況其實(shí)是很多條鏈:
(8,30)(30,112)(112,418)…
(27,240)(240,)…
(64,1020)(1020, )…
我們發(fā)現(xiàn)這些數(shù)很多是相連的,而不想連的數(shù)彼此之間開(kāi)頭都是i * i * i,再通過(guò)枚舉幾個(gè)總結(jié)規(guī)律,每個(gè)鏈的開(kāi)始都是a=i * i * i,后面緊跟著是(a * i * i )-pre,pre是上一組
找到規(guī)律,我們預(yù)處理出所有情況,然后排序,找到每個(gè)情況的上限值,直接二分就行
代碼:
#include<bits/stdc++.h> #define debug(a,b) printf("%s = %d\n",a,b); typedef long double ll; using namespace std; //Fe~Jozky const ll INF=0x3f3f3f3f; inline int read(){int s=0,w=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();//s=(s<<3)+(s<<1)+(ch^48);return s*w; } ll inf=1e18; const int N=1e6; long double a[7000007]; int tot=0; void init(){for(int i=2;i<=N;i++){ll x=1ll*i*i*i;a[++tot]=x;ll t=x*i*i-i;if(t>inf)continue;ll prea=x;while(t<inf){a[++tot]=t;t=1ll*t*i*i-prea;prea=a[tot];}}sort(a+1,a+1+tot); } int main() {init();int t=read();while(t--){long double x;cin>>x;int id=lower_bound(a+1,a+1+tot,x)-a;if(a[id]>x)id--;cout<<id+1<<endl;}return 0; }總結(jié)
以上是生活随笔為你收集整理的Math(牛客多校第三场)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Counting Triangles
- 下一篇: Black and white