1
2
2018
0

找规律

BZOJ1228

这个SG规律真难找,找了半天也找不出最后看了题解。

这个规律不是O(1)的,是O(log)的。

SG[i/2][j/2]->SG[i][j]

int GetSG(int n,int m){
    if((n&1)&&(m&1)) return 0;
    if(!(n&1)&&!(m&1)) return GetSG(n/2,m/2)+1;
    return (n&1)?GetSG((n+1)/2,m/2)+1:GetSG(n/2,(m+1)/2)+1;
}
#include<cstdio>
#include<cstring>
#include<iostream>
#include<stdlib.h>
#include<ctime>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LL long long
#define FOR(i,a,b) for (int i=a;i<=b;i++)
#define FORD(i,a,b) for (int i=a;i>=b;i--)
using namespace std;
typedef pair<int,int> pa;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
int tmp[500010],ts,mex,sg[555][555];
int main(){
	FOR(t,2,60)
		FOR(j,1,t-1){
			int i=t-j;
			ts=0;
			FOR(k,1,i-1) tmp[++ts]=sg[k][i-k];
			FOR(k,1,j-1) tmp[++ts]=sg[k][j-k];
			sort(tmp+1,tmp+ts+1);
			ts=unique(tmp+1,tmp+ts+1)-tmp-1;
			mex=-1;
			FOR(k,1,ts)
				if (tmp[k]==mex+1) ++mex;
			sg[i][j]=mex+1;
		}
	FOR(i,1,30){
		FOR(j,1,30) printf("%d ",sg[i][j]);
		puts("");
	}
	return 0;
}

http://www.lydsy.com/JudgeOnline/problem.php?id=3288

欧拉函数前缀积。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<stdlib.h>
#include<ctime>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LL long long
#define FOR(i,a,b) for (int i=a;i<=b;i++)
#define FORD(i,a,b) for (int i=a;i>=b;i--)
using namespace std;
typedef pair<int,int> pa;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
const int MO=1e9+7;
int n,phi[1000010],p[1000010],pr;
LL ans;
bool u[1000010];
LL pw(LL x,LL y){
	LL t=1;
	for (;y;y>>=1){
		if (y&1) t=t*x%MO;
		x=x*x%MO;
	}
	return t;
}
void getp(){
	phi[1]=1;
	FOR(i,2,n){
		if (!u[i]){p[++pr]=i;phi[i]=i-1;}
		FOR(j,1,pr){
			if (i*p[j]>n) break;
			u[i*p[j]]=1;
			if (i%p[j]==0){phi[i*p[j]]=phi[i]*p[j];break;}
			else phi[i*p[j]]=phi[i]*phi[p[j]];
		}
	}
}
int main(){
	cin>>n;
	getp();
	ans=1;
	FOR(i,1,n) ans=ans*phi[i]%MO;
	cout<<ans<<endl;
	return 0;
}
#include<cstdio>
#include<cstring>
#include<iostream>
#include<stdlib.h>
#include<ctime>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LL long long
#define FOR(i,a,b) for (int i=a;i<=b;i++)
#define FORD(i,a,b) for (int i=a;i>=b;i--)
using namespace std;
typedef pair<int,int> pa;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
const int MO=1e9+7;
int a[1010][1010],n,k;
LL pw(LL x,LL y){
	LL t=1;
	for (;y;y>>=1){
		if (y&1) t=t*x%MO;
		x=x*x%MO;
	}
	return t;
}
LL det(){
	LL ans=1;
	FOR(i,1,n){
		k=0;
		FOR(j,i,n)
			if (a[j][i]!=0){k=j;break;}
		if (!k) return 0ll;
		if (i!=k){
			FOR(j,1,n) swap(a[i][j],a[k][j]);
			ans=-ans;
		}
		LL t=pw(a[i][i],MO-2);
		FOR(j,i+1,n)
			if (a[j][i]!=0){
				LL w=-t*a[k][i]%MO;
				FOR(k,i,n) (a[j][k]+=a[i][k]*w)%=MO;
			}
	}
	FOR(i,1,n) ans=ans*a[i][i]%MO;
	return ans;
}
int main(){
	cin>>n;
	FOR(i,1,n)
		FOR(j,1,n)
			a[i][j]=__gcd(i,j);
	cout<<det()<<endl;
	return 0;
}
Category: 技巧 | Tags: | Read Count: 53

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com