zoukankan      html  css  js  c++  java
  • cf589div2

    https://codeforces.com/contest/1228/problem/A

    #include<iostream>
    #include<cstdio>
     
    using namespace std;
     
    int pd(int x) {
    	int a[10] = {};
    	while(x) {
    		if(a[x%10]) return 0;
    		a[x%10]++;
    		x /= 10;
    	}
    	return 1;
    }
     
    int main(){
    	int l,r; scanf("%d%d", &l, &r);
    	for(int i = l; i <= r; i++)
    	{
    		if(pd(i)) {
    			printf("%d
    ", i); return 0;
    		}
    	}
    	printf("-1
    ");
    	return 0;
    }
    /*
    input
    121 130
    
    output
    123
    
    input
    98766 100000
    
    output
    -1
    */

      

    https://codeforces.com/contest/1228/problem/B

    //题解 如题意模拟,计算剩下不是必须要填的格子 2^cnt(cnt不大 快速幂用不用都行)
    //但是要判断下 当cnt为0的时候 输出1
    //还有当条件冲突了的时候 表示不可能存在 输出为 0
    //小技巧 可以用或运算 条件冲突时值便为更大的值 3
    #include<bits/stdc++.h>
    using namespace std;//cf589div2b
    #define _for(i,a,b) for(int i = (a); i < (b); i++)
    #define _rep(i,a,b) for(int i = (a); i <= (b); i++)
    #define ll long long
    const ll mod = 1e9+7;
    
    int l,r, cnt = 0;
    int main() {//ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        scanf("%d%d", &l, &r);
        vector<vector<int> > f(l+5, vector<int>(r+5, 0));
        _rep(i,1,l) {
            int k;  scanf("%d", &k); 
            _rep(j,1,k) f[i][j] |= 1;
            if(k+1 <= r)  f[i][k+1] |= 2;
        }
        _rep(i,1,r)    {
            int k;  scanf("%d", &k); 
            _rep(j,1,k) f[j][i] |= 1;
            if(k+1 <= l)  f[k+1][i] |= 2;
        }
        ll ans = 1;
        _rep(i,1,l) _rep(j,1,r)  if(!f[i][j]) ans *= 2, ans %= mod;
        _rep(i,1,l) _rep(j,1,r)  if(f[i][j] == 3) ans *= 0;
        //if(!f[i][j] && i>=c[i] && j>=d[j]) cnt++;
        //printf("cnt = %d
    ", cnt);
        printf("%lld
    ", ans);
        return 0;
    }
    
    /*
    3 4 
    0 3 1
    0 2 3 0
    output
    2
    
    1 1
    0
    1
    output
    0
    
    19 16
    16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12
    6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4
    output          2^47%mod  = 487370169
    797922655 == 2^51%mod
    */

    https://codeforces.com/contest/1228/problem/C

    将公式推导下 能看出f(x,1) *……*f(x,n)的结果就是 x 的质因子p1*……*pk 

    1*……* n除去非x的质因子的因子剩下的答案模1e9+7便是了,但是实际操作比较麻烦

    经过一系列推导(魔法) 可以得出 结果等于 pi^(n/pi) (i  1……k)的乘积

    n!  可被 2的x次方整除   x = 0; while(n > 0) {n /= 2, x += n;}  可算出x, 有意思(具体数学的第四章 数论的4.4节阶乘的因子中有相关推导)

    其他的质因子指数求法 同理, 代码如下  

    /*
    input
    10 2
    output
    2
    input
    20190929 1605
    output
    363165664
    input
    947 987654321987654321
    output
    593574252
    */
    //vector<vector<int> > f(l+5, vector<int>(r+5, 0));
    #include<bits/stdc++.h>
    
    using namespace std;
    #define ll long long
    const ll mod = (int)1e9+7;
    ll powmod(ll x, ll a){
    	if(a == 0) return 1;
    	if(a & 1) return x*powmod(x, a-1)%mod;
    	return powmod(x*x%mod, a/2)%mod;
    }
    int main(){
    	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    	ll x, n;
    	cin >> x >> n;
    	set<ll> dv;
    	for(int d = 2; d*d <= x; d++)
    		while(x%d == 0)
    			dv.insert(d), x /= d;
    	if(x > 1) dv.insert(x);
    	ll ans = 1;
    	for(ll d : dv){
    		ll g = 0, r = n;
    		while(r > 0) r /= d, g += r;
    		ans *= powmod(d, g); ans %= mod;
    	}
    	return cout << (int)ans << '
    ', 0;
    }
    

      

  • 相关阅读:
    super.getClass().getName()方法调用的返回
    外观模式(Façade Pattern)
    Framework 4.0 将何去何从
    SQL Server 2005 第一篇 引言
    抽象工厂模式(Abstract Factory)
    浅谈分页技术
    垃圾邮件
    读书时的软件开发梦
    写技术博客的一个原因应该是寂寞吧
    当下10大最热门的网站开发技术
  • 原文地址:https://www.cnblogs.com/163467wyj/p/11614706.html
Copyright © 2011-2022 走看看