B君的教育【省选模拟赛】

复数+短除法


本文总阅读量
Posted by yjjr's blog on March 12, 2018

标签:数学

题目

这里写图片描述

分析

类似二进制拆分,短除法

直接看代码就好

复杂度O(log n)

code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<complex>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
#define lson (x<<1)
#define rson (x<<1|1)
#define mid ((l+r)>>1)
#define pi acos(-1)
#define mp make_pair
#define pb push_back
#define pa pair<int,int>
#define fi first
#define se second
#define lowbit(x) ((x)&(-x))
using namespace std;
inline ll read(){
	ll f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
inline ll getgcd(ll x,ll y){return !x?y:getgcd(y%x,x);}
inline ll getlcm(ll x,ll y){return x/getgcd(x,y)*y;}
inline ll qpow(int x,int y,int p){
	ll re=1;
	while(y){
	   	if(y&1)re=(re*x)%p;
		y>>=1,x=(x*x)%p;
	}
	return re;
}
//**********head by yjjr**********
complex<ll> n,p,u;
ll x,y,num;int ans[206];
int main()
{
	x=read(),y=read();
	n=complex<ll>(x,y);
	p=complex<ll>(-1,1);
	while(n!=complex<ll>(0,0)){
		u=n/p;
		if(u*p!=n){
			ans[num]=1;
			n-=complex<ll>(1,0);
		}
		n/=p;num++;//cout<<n<<endl;
	}
	rep(i,0,num)if(ans[i])printf("%d\n",i);
	return 0;
}
本文可以转载,但必须附上原文链接,否则你会终生找不到妹子!!!欢迎关注我的CSDN: ahyjjr