zoukankan      html  css  js  c++  java
  • 「十二省联考 2019」骗分过样例(提答+数论+乱搞):

    「十二省联考 2019」骗分过样例(提答+数论+乱搞):

    https://loj.ac/problem/3050

    两个小时大概能玩个70+分,应该达到了平均水平。

    1_998244353

    没什么好说的,快速幂,对于test#3,可以直接高精度二进制分解,也可以用欧拉定理优化。

    1?

    发现得到的数都很小,因为模数>最大值,所以取最大值,往上增个1k多久发现有解了。

    1?+

    考虑如果有(19^x和19^y(x>y)),做个差(19^x-19^y=19^y(19^{x-y}-1))

    如果(x,y,x-y)同时存在,那么我们就可以知道上面的所有值,从而得到:
    (mo|19^x-19^y-19^y(19^{x-y}-1))

    一种方法是找到一组((x,y,x-y)),然后枚举所有约数判,这个由于数太大了,所以很难写。

    发现可以找到很多组((x,y,x-y)),取所有的结果的gcd就好了。

    1_wa998244353

    发现有负数,大力猜测是用了int溢出了。

    实验后果然如此,但是#7指数很大,这个溢出又不能快速幂,怎么办?

    这里脑抽了想不到怎么做。

    注意到溢出后就和随机没什么区别,由生日悖论,循环节长度大概是(sqrt {mo})

    2p

    首先发现每一行的长度就是r-l+1,大力猜测是个区间什么的。

    然后一看2、3、5、7,质数没得跑了。

    (r<=10^{12})可以区间筛,(r<=10^{18})可以miller-rabin,需要卡一下下常(先判断是不是前20个质数的倍数)。

    2u

    还是区间,看到有0、+1、-1,(mu)没得跑了。

    对每个数,如果能pollard-pho分解质因数就好了,可惜分不得。

    考虑先用(10^6)内的质数去区间分解,那么剩下的每个数最多由两个质数乘起来。

    去掉完全平方数和质数后,剩下的数一定是两个质数的乘积。

    miller-rabin上去判断TLE了,优化:

    1.只判断(>10^{12})的数。

    2.随机次数少点发现也能过。

    2g

    打死想不到原根系列,想到了就是基础知识了。

    判断一个(x)是不是原根,只需要判断(x^{(mo-1)/p(p是(mo-1)的质因子)})是不是都不是1.

    找到一个原根后,其它的原根可以通过(x^{j}(gcd(j,mo-1)=1))得到。

    2g?

    枚举(10^9~2*10^9)的所有质数判断,大概十分钟。

    Code:


    #include<bits/stdc++.h>
    #define fo(i, x, y) for(int i = x, _b = y; i <= _b; i ++)
    #define ff(i, x, y) for(int i = x, _b = y; i <  _b; i ++)
    #define fd(i, x, y) for(int i = x, _b = y; i >= _b; i --)
    #define ll long long
    #define pp printf
    #define hh pp("
    ")
    using namespace std;
    	
    namespace sub1 {
    	ll ksm(ll x, ll y, ll mo) {
    		ll s = 1;
    		for(; y; y /= 2, x = x * x % mo)
    			if(y & 1) s = s * x % mo;
    		return s;
    	}
    	
    	const int mo = 998244353;
    	
    	const int N = 1005;
    	
    	int n;
    	char s[N]; int len;
    
    	void work() {
    		scanf("%d", &n);
    		fo(i, 1, n) {
    			scanf("%s", s + 1);
    			len = strlen(s + 1);
    			ll y = 0;
    			fo(j, 1, len) {
    				y = (y * 10 + s[j] - '0');
    				y %= (mo - 1);
    			}
    			pp("%lld
    ", ksm(19, y, mo));
    		}
    	}
    }
    
    ll ksm_19(char *s, ll mo) {
    	int n = strlen(s + 1);
    	int a[100];
    	fo(i, 1, n) a[n - i + 1] = s[i] - '0';
    	ll v = 1, x = 19;
    	while(n > 0) {
    		ll y = 0;
    		fd(i, n, 1) {
    			y = y * 10 + a[i];
    			a[i] = y / 2; y %= 2;
    		}
    		if(y & 1) v = v * x % mo;
    		x = x * x % mo;
    		while(n > 0 && a[n] == 0) n --;
    	}
    	return v;
    }
    
    namespace sub2 {
    	const int N = 1e5 + 5;
    	
    	int n;
    	
    	ll ans[N];
    
    	char s[N][50];
    	
    	ll mo;
    	
    	void work() {
    		mo = 1145141;
    		scanf("%d", &n);
    		fo(i, 1, n) {
    			scanf("%s", s[i] + 1);
    		}
    		fo(i, 1, n) {
    			pp("%lld
    ", ksm_19(s[i], mo));
    		}
    
    	}
    }
    
    namespace sub3 {
    	const int N = 10005;
    	
    	int n;
    	ll a[N];
    	
    	ll mo = 5211600617818708273ll;	
    	
    	ll mul(ll x, ll y, ll mo) {
    		ll z = (long double) x * y / mo;
    		z = x * y - z * mo;
    		if(z < 0) z += mo; else if(z >= mo) z -= mo;
    		return z;
    	}
    	
    	ll ksm(ll x, ll y, ll mo) {
    		ll s = 1;
    		for(; y; y /= 2, x = mul(x, x, mo))
    			if(y & 1) s = mul(s, x, mo);
    		return s;
    	}
    	
    	void work() {
    		scanf("%d", &n);
    		fo(i, 1, n) {
    			scanf("%lld", &a[i]);
    			pp("%lld
    ", ksm(19, a[i], mo));
    		}
    	}
    }
    
    namespace sub4 {
    	const int mo = 998244353;
    	
    	int a[10000005];
    	
    	map<int, int> bz;
    	
    	int n;
    	
    	void work() {
    		int s = 1; a[0] = s;
    		int l, r;
    		fo(i, 1, 1e7) {
    			s = s * 19 % mo;
    			if(bz[s]) {
    				l = bz[s], r = i - 1;
    				break;
    			}
    			bz[s] = i;
    			a[i] = s;
    		}
    		scanf("%d", &n);
    		fo(i, 1, n) {
    			ll x; scanf("%lld", &x);
    			if(x <= r) {
    				pp("%d
    ", a[x]);
    			} else {
    				x -= l;
    				x %= (r - l + 1);
    				pp("%d
    ", a[l + x]);
    			}
    		}
    	}
    }
    
    namespace sub5 {
    	
    	const int N = 1e6 + 5;
    	
    	int p[N], p0, bp[N];
    	
    	void sieve(int n) {
    		fo(i, 2, n) {
    			if(!bp[i]) {
    				p[++ p0] = i;
    			}
    			for(int j = 1; i * p[j] <= n; j ++) {
    				bp[i * p[j]] = 1;
    				if(i % p[j] == 0) break;
    			}
    		}
    	}
    	
    	int n;
    	int bz[N];
    	
    	ll mul(ll x, ll y, ll mo) {
    		ll z = (long double) x * y / mo;
    		z = x * y - z * mo;
    		if(z < 0) z += mo; else if(z >= mo) z -= mo;
    		return z;
    	}
    	
    	#define ull unsigned long long
    	ull rx = 1e9 + 7;
    	ll randx(ll x, ll y) {
    		rx ^= rx << 17;
    		rx ^= rx >> 23;
    		rx ^= rx << 39;
    		return rx % (y - x + 1) + x;
    	}
    		
    	ll ksm(ll x, ll y, ll mo) {
    		ll s = 1;
    		for(; y; y /= 2, x = mul(x, x, mo))
    			if(y & 1) s = mul(s, x, mo);
    		return s;
    	}
    	
    	int pd(ll n) {
    		fo(i, 1, 20) if(n == p[i]) return 1;
    		fo(i, 1, 20) if(n % p[i] == 0) return 0;
    		ll s = n - 1, c = 0;
    		while(s % 2 == 0) s /= 2, c ++;
    		fo(T, 1, 20) {
    			ll x = randx(1, n - 1);
    			x = ksm(x, s, n);
    			fo(j, 1, c) {
    				ll y = mul(x, x, n);
    				if(y == 1 && x != 1 && x != n - 1) return 0;
    				x = y;
    			}
    			if(x != 1) return 0;
    		}
    		return 1;
    	}
    	
    	void work() {
    		sieve(1e6);
    		ll x, y;
    		scanf("%d", &n);
    		fo(i, 1, n) {
    			scanf("%lld %lld", &x, &y);
    			for(ll i = x; i <= y; i ++) {
    				putchar(pd(i) ? 'p' : '.');
    			}
    			hh;
    		}
    	}
    }
    
    namespace sub6 {
    	const int N = 1e6 + 5;
    	
    	int p[N], p0, bp[N];
    	
    	void sieve(int n) {
    		fo(i, 2, n) {
    			if(!bp[i]) {
    				p[++ p0] = i;
    			}
    			for(int j = 1; i * p[j] <= n; j ++) {
    				bp[i * p[j]] = 1;
    				if(i % p[j] == 0) break;
    			}
    		}
    	}
    	
    	int n;
    	
    	int bz[N];
    	ll a[N], mu[N];
    	
    	#define ull unsigned long long
    	ull rx = 1e9 + 7;
    	ll randx(ll x, ll y) {
    		rx ^= rx << 17;
    		rx ^= rx >> 23;
    		rx ^= rx << 39;
    		return rx % (y - x + 1) + x;
    	}
    			
    	ll mul(ll x, ll y, ll mo) {
    		ll z = (long double) x * y / mo;
    		z = x * y - z * mo;
    		if(z < 0) z += mo; else if(z >= mo) z -= mo;
    		return z;
    	}
    	
    	ll ksm(ll x, ll y, ll mo) {
    		ll s = 1;
    		for(; y; y /= 2, x = mul(x, x, mo))
    			if(y & 1) s = mul(s, x, mo);
    		return s;
    	}
    	
    	int pd(ll n) {
    		ll s = n - 1, c = 0;
    		while(s % 2 == 0) s /= 2, c ++;
    		fo(T, 1, 3) {
    			ll x = randx(1, n - 1);
    			x = ksm(x, s, n);
    			fo(j, 1, c) {
    				ll y = mul(x, x, n);
    				if(y == 1 && x != 1 && x != n - 1) return 0;
    				x = y;
    			}
    			if(x != 1) return 0;
    		}
    		return 1;
    	}
    	
    	void work() {
    		sieve(1e6);
    		scanf("%d", &n);
    		fo(ii, 1, n) {
    			ll x, y;
    			scanf("%lld %lld", &x, &y);
    			fo(i, 0, y - x) {
    				a[i] = i + x;
    				mu[i] = 1;
    			}
    			fo(_i, 1, p0) {
    				ll i = p[_i];
    				ll j = x / i * i; if(j < x) j += i;
    				while(j <= y) {
    					ll &v = a[j - x], &v2 = mu[j - x];
    					int zs = 0;
    					while(v % i == 0) v /= i, zs ++;
    					if(zs > 1) v2 = 0; else v2 = -v2;
    					j += i;
    				}
    			}
    			fo(i, 0, y - x) {
    				if(a[i] > 1) {
    					ll t = sqrt(a[i]);
    					if(t * t == a[i]) {
    						mu[i] = 0;
    					} else {
    						if(a[i] <= 1e12 || pd(a[i]))
    							mu[i] = -mu[i];
    					}
    				}
    				putchar(mu[i] == 1 ? '+' : (mu[i] == -1 ? '-' : '0'));
    			}
    			hh;
    		}
    	}
    }
    
    namespace sub7 {
    	const int N = 1e6 + 5;
    	
    	int p[N], p0, bp[N];
    	
    	void sieve(int n) {
    		fo(i, 2, n) {
    			if(!bp[i]) {
    				p[++ p0] = i;
    			}
    			for(int j = 1; i * p[j] <= n; j ++) {
    				bp[i * p[j]] = 1;
    				if(i % p[j] == 0) break;
    			}
    		}
    	}
    	
    	int n;
    	
    	ll mo;
    	
    	ll ksm(ll x, ll y) {
    		ll s = 1;
    		for(; y; y /= 2, x = x * x % mo)
    			if(y & 1) s = s * x % mo;
    		return s;
    	}
    	
    	int d[100005], d0;
    	
    	ll u[100], u0;
    	void fen(ll mo) {
    		d0 = u0 = 0;
    		ll x = mo - 1;
    		for(int i = 1; i <= p0 && p[i] * p[i] <= x; i ++) if(x % p[i] == 0) {
    			u[++ u0] = p[i];
    			while(x % p[i] == 0) x /= p[i];
    		}
    		if(x > 1) u[++ u0] = x;
    		fo(i, 1, u0) d[++ d0] = (mo - 1) / u[i];
    	}
    	
    	int pdg(ll x) {
    		fo(i, 1, d0) if(ksm(x, d[i]) == 1)
    			return 0;
    		return 1;
    	}
    	
    	int bz[14000005];
    	
    	void work() {
    		sieve(1e6);
    		scanf("%d", &n);
    		fo(T, 1, n) {
    			ll x, y;
    			scanf("%lld %lld", &x, &y);
    			if(x == 233333333) {
    				mo = 1515343657;
    			} else scanf("%lld", &mo);
    			fen(mo);
    			if(y - x <= 8e5) {
    				fo(i, x, y)  putchar(pdg(i) ? 'g' : '.');
    			} else {
    				ll g;
    				for(g = 2; g <= 11; g ++) if(pdg(g))
    					break;
    				ll s = 1;
    				fo(i, 1, mo - 1) {
    					s = s * g % mo;
    					int ky = 1;
    					fo(j, 1, u0) if(i % u[j] == 0) ky = 0;
    					if(ky) bz[s] = 1;
    				}
    				fo(i, x, y) putchar(bz[i] ? 'g' : '.');
    			}
    			hh;
    		}
    	}
    }
    
    string str;
    
    int main() {
    	freopen("software.in", "r", stdin);
    	freopen("software.out", "w", stdout);
    	cin >> str;
    	if(str == "1_998244353") {
    		sub1 :: work();
    		return 0;
    	}
    	if(str == "1?") {
    		sub2 :: work();
    		return 0;
    	}
    	if(str == "1?+") {
    		sub3 :: work();
    		return 0;
    	}
    	if(str == "1wa_998244353") {
    		sub4 :: work();
    		return 0;
    	}
    	if(str == "2p") {
    		sub5 :: work();
    		return 0;
    	}
    	if(str == "2u") {
    		sub6 :: work();
    		return 0;
    	}
    	if(str == "2g" || str == "2g?") {
    		sub7 :: work();
    		return 0;
    	}
    }
    
  • 相关阅读:
    【Educational Codeforces Round 101 (Rated for Div. 2) C】Building a Fence
    【Codeforces Round #698 (Div. 2) C】Nezzar and Symmetric Array
    【Codeforces Round #696 (Div. 2) D】Cleaning
    【Codeforces Round #696 (Div. 2) C】Array Destruction
    【Educational Codeforces Round 102 D】Program
    【Educational Codeforces Round 102 C】No More Inversions
    【Good Bye 2020 G】Song of the Sirens
    【Good Bye 2020 F】Euclid's nightmare
    使用mobx入门
    requestAnimationFrame 控制速度模拟setinterval
  • 原文地址:https://www.cnblogs.com/coldchair/p/12584572.html
Copyright © 2011-2022 走看看