2020牛客多校第四场

B 打表

#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define INF 0x3f3f3f3f
#define pi 3.141592654
typedef long long ll;
const int N = 2e6+5;
ll vis[N] = {1,1};
ll n,c,ans,cnt=0;
ll prim[N] ;///记录素数个数
void fun(){///欧筛
	for (ll i = 2; i < N; i++) {
		if (vis[i] == 0) 	prim[++cnt] = i;///记录素数
		for (ll j = 1; (j <= cnt) && (i*prim[j]) < N; j++) {
			vis[i*prim[j]] = 1;
			if (i%prim[j] == 0)break;
		}
	}
}
ll pow_mod(ll a, ll n, ll m){///a的n次方模m
    if(n == 0)  return 1;
    int x = pow_mod(a, n/2, m);
    ll ans = (ll)x * x % m;
    if(n % 2 == 1) ans = ans *a % m;
    return ans;
}
ll gcdl(ll a,ll b){return b==0?a:gcdl(b,a%b);}
int gcd(int a,int b)   {return a%b==0?b:gcd(b,a%b);}
int mi(int a,int b)    {return a<b?a:b;}
int ma(int a,int b)    {return a>b?a:b;}
int abs(int a)         {return a>0?a:-a;}
void prep(){int ckt=0;     for(int i = 1 ; i<=2;i++)	ckt++;}
int main(){
    fun();
    //printf("%d\n",cnt);
    int t; scanf("%d",&t);
    while(t--){
        scanf("%lld %lld",&n,&c);
        ll ans = 0;
        if(vis[n]){
            for(ll i = 1 ; i <= cnt && n>1 && prim[i]*prim[i]<=n; i++){
                while(n%prim[i] == 0){
                    n/=prim[i];ans++;
                }//printf("%lld  %lld\n",n,ans);
                if(!vis[n]){
                    ans++;break;
                }
            }//printf("%lld\n",cnt);
        }else ans++;
        printf("%lld\n",pow_mod(c,ans,mod));
    }
    return 0;
}


F 分类讨论

#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define INF 0x3f3f3f3f
#define pi 3.141592654
typedef long long ll;
const int N = 2e6+5;
ll gcdl(ll a,ll b){return b==0?a:gcdl(b,a%b);}
int gcd(int a,int b)   {return a%b==0?b:gcd(b,a%b);}
int mi(int a,int b)    {return a<b?a:b;}
int ma(int a,int b)    {return a>b?a:b;}
int abs(int a)         {return a>0?a:-a;}
void prep(){int ckt=0;     for(int i = 1 ; i<=2;i++)	ckt++;}
int main(){
    int t;  scanf("%d",&t);
    int ac,ad,bc,bd;
    while(t--){
        int k;
        scanf("%d %d %d %d",&ac,&ad,&bc,&bd);
        if(ac<=bc&&ad>=bd)         printf("AB//CD\n");
        else if(ac >= bc && ad <= bd)   printf("AB//DC\n");
        else if(ac <= bc && ad <= bd){
            if(bc>bd)   printf("AB//CD\n");
            else        printf("AB//DC\n");
        }
        else if(ac >= bc && ad>= bd){
            if(ac<ad)   printf("AB//CD\n");
            else        printf("AB//DC\n");
        }
    }
}


H 构造

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> pll;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
ll qpow(ll base, ll n){ll ans = 1; while (n){if (n & 1) ans = ans * base % mod; base = base * base % mod; n >>= 1;} return ans;}
ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}
int ans[N], v[N];
int main(){
    int t;
    cin >> t;
    while (t --){
        int tot = 0;
        int n;
        scanf("%d", &n);
        for (int i = 1; i <= n + 1; ++ i) v[i] = 0;
        for (int i = 3; i <= n; i += 2){
            if (!v[i]){
                for (int j = i; j <= n; j += i){///不能为前面质数的倍数
                    if (j % 2 == 0 || v[j]) continue;
                    v[j] = 1;
                    ans[++ tot] = j;
                }
                if (tot % 2 == 1) {///多出来一个;尝试与i*2凑一个
                    int x = i * 2;
                    if (x <= n) {
                        v[x] = 1;
                        ans [++ tot] = x;
                    }else -- tot;
                }
            }
        }
        for (int i = 2; i <= n; i += 2){///2的倍数剩下的
            if (!v[i]) ans[++ tot] = i;
        }
        if (tot % 2 == 1) -- tot;
        printf("%d\n", tot / 2);
        for (int i = 1; i <= tot; i += 2){
            printf("%d %d\n", ans[i], ans[i + 1]);
        }
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值