[bzoj 2242]계산기 이산 대수

2609 단어 bzoj이산 대수
AC 채널:http://www.lydsy.com/JudgeOnline/problem.php?id=2242 
[토로]
삼 합 일의 템 플 릿 문제.쾌속 멱+확장 gcd+이산 대수
이 세 가 지 를 배 운 사람 은 다 할 수 있 겠 지,아니 야...전송 문:http://www.cnblogs.com/chty/p/6022641.html
쓸 때 손 이 싸 서 하 쉬 시 계 를 잘못 써 서 한참 동안 바 꿨 는데..................................................
못 생 긴 코드 붙 이기: 
/*************
  bzoj 2242
  by chty
  2016.11.9
*************/
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define FILE "read"
#define MAXN 99991
typedef long long ll;
struct node{ll v,f,num;}hash[MAXN+10];
ll a,b,mod;
inline ll read()
{
    ll x=0,f=1;  char ch=getchar();
    while(!isdigit(ch))  {if(ch=='-')  f=-1;  ch=getchar();}
    while(isdigit(ch))  {x=x*10+ch-'0';  ch=getchar();}
    return x*f;
}
void insert(ll v,ll x)
{
    ll temp=v%MAXN;
    while(hash[temp].f&&hash[temp].v!=v) {temp++; if(temp>MAXN) temp-=MAXN;}
    if(!hash[temp].f) hash[temp].f=1,hash[temp].v=v,hash[temp].num=x;
}
ll find(ll v)
{
    ll temp=v%MAXN;
    while(hash[temp].f&&hash[temp].v!=v) {temp++; if(temp>MAXN) temp-=MAXN;}
    if(!hash[temp].f)  return -1;
    else return hash[temp].num;
}
ll gcd(ll a,ll b) {return !b?a:gcd(b,a%b);}
ll exgcd(ll a,ll b,ll &x,ll &y)
{
    if(!b) {x=1; y=0; return a;}
    ll g=exgcd(b,a%b,x,y);
    ll t=x;x=y;y=t-a/b*y;
    return g;
}
void solve1(){ll sum=1;for(;b;b>>=1,a=a*a%mod)if(b&1)sum=sum*a%mod;printf("%d
",sum);} void solve2() { ll x,y,d=exgcd(a,mod,x,y); if(b%d) {printf("Orz, I cannot find x!
");return;} ll t=mod/d; while(x<0) x+=t; while(x>=t) x-=t; printf("%lld
",x*b%mod); } void solve3() { if(mod==1) {puts("0"); return;} a%=mod;b%=mod; ll ret(1); for(ll i=0;i<=50;i++) {if(ret==b) {printf("%lld
",i); return; ret=ret*a%mod;}} ll temp,ans(1),cnt(0); while((temp=gcd(a,mod))!=1) { if(b%temp) {printf("Orz, I cannot find x!
");return;} mod/=temp; b/=temp; ans=ans*(a/temp)%mod; cnt++; } ll m=(ll)sqrt(mod*1.0),t(1); for(ll i=0;i

 

좋은 웹페이지 즐겨찾기