2020.9.22训练

[Contest #16]小 C 的数论习题

CRT板子题,但是题目中要求输出的是整数,所以res=0的时候我们输出232332333。

#include <bits/stdc++.h>
//#define int long long
using namespace std;
const int N=1e5+10;
int a[10],m[10],n=3;
typedef long long ll;
ll exgcd(ll a,ll b,ll &x,ll &y)
{
    if(b==0)
    {
        x=1,y=0;
        return a;
    }
    ll c=exgcd(b,a%b,x,y);
    ll t=x;
    x=y;
    y=t-a/b*y;
    return c;
}
ll inv(ll a,ll p)// 求 a%p 的乘法逆元
{
    ll x,y;
    exgcd(a,p,x,y);
    return (x%p+p)%p;
}
ll CRT()
{
    ll ans=0,M=1;
    for(int i=1;i<=n;i++)
        M*=m[i];
    for(int i=1;i<=n;i++)
    {
        ll tmp=M/m[i];
        ans=(ans+a[i]*tmp%M*inv(tmp,m[i])%M)%M;
    }
    return (ans+M)%M;
}
void solve()
{
    scanf("%d%d%d",&a[1],&a[2],&a[3]);
    m[1]=23,m[2]=233,m[3]=2333;
    int res=CRT();
    if(!res) cout<<1ll*23*233*2333<<endl;
    else cout<<res<<endl;
}
signed main(){
    solve();
#ifndef ONLINE_JUDGE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}

C1360 [Contest #9]【XR-3】小道消息

根据:伯特兰-切比雪夫定理。我们可以知道对于n>3的时候我们可以找到一个p在[n,2n]之间,所以当我们p是一个质数的时候如果他在[n,2n]内那么直接一天就可以,否则在[1,n]里需要多一天传递到二倍区间。

#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
const int N=1e5+10;
int fun(int x)
{
    for(int i=2;i<=sqrt(x);i++){
        if(x%i==0) return 1;
    }
    return 0;
}
void solve()
{
    ll n,k; cin>>n>>k;
//    cout<<fun(k+1)<<endl;
    if(!fun(k+1)&&(k+1>((n+1)>>1))) cout<<1<<'\n';
    else cout<<2<<'\n';
}
signed main(){
    solve();
#ifndef ONLINE_JUDGE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}

C1635 [Wannafly冬令营2018Day1]拆拆拆数

如果是互质就直接输出就行了。如果不是我们可以利用2和所有的奇数互质,3和大部分的偶数都是互质的。然后直接10以内的循环就可以跑出来(不会证明)。

#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
const int N=1e5+10;
void solve()
{
    int a,b; cin>>a>>b;
    if(__gcd(a,b)==1){
        cout<<1<<'\n';
        cout<<a<<' '<<b<<'\n';
    }else{
        for(int i=1;i<=10;i++){
            for(int j=1;j<=10;j++){
                if(__gcd(i,j)==1&&__gcd(a-i,b-j)==1){
                    cout<<2<<'\n';
                    cout<<i<<' '<<j<<'\n';
                    cout<<a-i<<' '<<b-j<<'\n';
                    return;
                }
            }
        }
    }
}
signed main(){
    int t; cin>>t;
    while(t--) solve();
#ifndef ONLINE_JUDGE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}

C1026 [欢乐赛]第002话 宝可梦中心大对决!

看到n很小就直接写暴力了。

#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
const int N=1e2+10;
int a[N],vis[N],n,res;
void dfs(int pos,int cnt)
{
    if(pos==n+1){
        for(int i=1;i<=n;i++){
            for(int j=i+1;j<=n;j++){
                if(vis[i]&&vis[j]&&__gcd(a[i],a[j])!=1) return;
            }
        }
        res=max(res,cnt);
        return;
    }
    if(vis[pos]) return;
    vis[pos]=1;
    dfs(pos+1,cnt+1);
    vis[pos]=0;
    dfs(pos+1,cnt);
}
void solve()
{
    res=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    dfs(1,0);
    cout<<res<<'\n';
}
signed main(){
    int t; cin>>t;
    while(t--) solve();
#ifndef ONLINE_JUDGE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}

Comet OJ - Contest #15 B

我们枚举每个点是其他三个点的外心的情况,然后统计答案。

#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
const int N=2e3+10;
int x[N],y[N];
int dis[N<<1];
int d(int i,int j)
{
    return abs(x[i]-x[j])*abs(x[i]-x[j])+abs(y[i]-y[j])*abs(y[i]-y[j]);
}
int cal(int x)
{
    return x*(x-1)*(x-2)/6;
}
void solve()
{
    int n; cin>>n;
    for(int i=1;i<=n;i++) cin>>x[i]>>y[i];
    int res=0;
    for(int i=1;i<=n;i++){
        int tot=0;
        for(int j=1;j<=n;j++) {
            if(i!=j) dis[++tot]=d(i,j);
        }
        sort(dis+1,dis+1+tot);
        for(int l=1,r=1;l<=tot;l=r){
            while(r<=tot&&dis[l]==dis[r]) r++;
            res+=cal(r-l);
        }
    }
    cout<<res<<endl;
}
signed main(){
    solve();
#ifndef ONLINE_JUDGE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值