Little Difference Gym - 101612L 分解类型的题

看了红博大佬的博客。。。


做这个题还是我太慌张。。。 上来想也不想就整了个质因数分解的板子。


赛后才知道就是暴力。。。当然是有技巧的暴力

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#define inf 0x3f3f3f3f
#define ms(x) memset(x, 0, sizeof(x))
#define ll long long
using namespace std;
const int N = 100007;
vector<ll>box[N];
int top = 0;
bool solve(ll n)
{
    ll tn = n;
    while(tn%2==0)
    {
        tn/=2;
    }
    if(tn==1) return false;
    box[top].push_back(n);
    for(ll i=2;i*i*i<=n;i++)
    {
        if(n%i==0)
        {
            ll tmp = n;
            vector<ll> o ;
            while(tmp%i==0)
            {
                tmp/=i;
                o.push_back(i);
            }
            while(tmp%(i+1)==0)
            {
                tmp/=(i+1);
                o.push_back(i+1);
            }
            if(tmp==1)
            {
                box[++top] = o;
            }
        }
    }
    ll ti = sqrt(n);
    if(ti*ti == n)
    {
        box[++top].push_back(ti);
        box[top].push_back(ti);
    }
    else if(ti*(ti+1)==n)
    {
        box[++top].push_back(ti);
        box[top].push_back(ti+1);
    }
    else if((ti-1)*(ti)==n)
    {
        box[++top].push_back(ti-1);
        box[top].push_back(ti);
    }
    return true;
}
int main()
{
    ll n;
    freopen("little.in","r",stdin);
    freopen("little.out","w",stdout);
    scanf("%lld", &n);
    if(!solve(n))
    {
        puts("-1");
        return 0;
    }
    printf("%d\n", top+1);
    for(int i=0;i<=top;i++)
    {
        printf("%d",box[i].size());
        for(int j=0;j<box[i].size();j++)
        {
            printf(" %lld", box[i][j]);
        }
        printf("\n");
    }

    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值