結果

問題 No.1200 お菓子配り-3
ユーザー tailstails
提出日時 2021-05-19 20:04:13
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 28 ms / 4,000 ms
コード長 2,104 bytes
コンパイル時間 533 ms
コンパイル使用メモリ 34,944 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-18 08:28:44
合計ジャッジ時間 1,339 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 3 ms
6,940 KB
testcase_18 AC 3 ms
6,944 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 5 ms
6,940 KB
testcase_21 AC 6 ms
6,940 KB
testcase_22 AC 6 ms
6,940 KB
testcase_23 AC 5 ms
6,944 KB
testcase_24 AC 5 ms
6,940 KB
testcase_25 AC 5 ms
6,940 KB
testcase_26 AC 5 ms
6,944 KB
testcase_27 AC 1 ms
6,940 KB
testcase_28 AC 5 ms
6,940 KB
testcase_29 AC 25 ms
6,940 KB
testcase_30 AC 28 ms
6,944 KB
testcase_31 AC 1 ms
6,940 KB
testcase_32 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:90:1: warning: return type defaults to 'int' [-Wimplicit-int]
   90 | main(){
      | ^~~~
main.c: In function 'main':
main.c:123:9: warning: implicit declaration of function 'write' [-Wimplicit-function-declaration]
  123 |         write(1,wbuf,wp-wbuf);
      |         ^~~~~
main.c:124:9: warning: implicit declaration of function '_exit'; did you mean '_Exit'? [-Wimplicit-function-declaration]
  124 |         _exit(0);
      |         ^~~~~
      |         _Exit

ソースコード

diff #

#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")

char*mmap();
#define rd_skip() while(*rp++>=48)
#define rd(v) int v=0;{int _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;}

char wbuf[1<<28];

#define WTHI(v) {int _z=v,_n=0;long _d=0;while(++_n,_d=_d<<8|0x30|_z%10,_z/=10);*(long*)wp=_d;wp+=_n;}
#define WTLO(v) {int _z=v,_n=8;long _d=0;while(_d=_d<<8|0x30|_z%10,_z/=10,--_n);*(long*)wp=_d;wp+=8;}
#define wt(v) WTHI(v)

#define rep(v,e) for(int v=0;v<e;++v)

#define SIEVE_N 46340
int nprimes;
int primes[SIEVE_N];
char sieve[SIEVE_N];

void mkprimes(){
	primes[nprimes++]=2;
	for(int i=3;i<SIEVE_N;i+=2){
		if(sieve[i]==0){
			primes[nprimes++]=i;
			for(int j=i*i;j<SIEVE_N;j+=i*2){
				sieve[j]=1;
			}
		}
	}
}

// Exact Division
// https://yukicoder.me/submissions/658591 by akakimidori
// https://min-25.hatenablog.com/entry/2017/08/20/171214

typedef struct{
	unsigned t,i;
} SEdev;

SEdev prime_edevs[SIEVE_N];

void mkedevs(){
	for(int i=1;i<nprimes;++i){
		unsigned p=primes[i];
		prime_edevs[i].t=~0u/p;
		unsigned x=p;
		x*=2-p*x;
		x*=2-p*x;
		x*=2-p*x;
		x*=2-p*x;
		prime_edevs[i].i=x;
	}
}

int divisors(int a,int*divs){
	int n=0;
	divs[n++]=1;
	{
		int k=__builtin_ctz(a);
		a>>=k;
		int n0=n*k;
		for(int j=0;j<n0;++j){
			divs[n++]=divs[j]*2;
		}
	}
	for(int i=1,p;p=primes[i],a>=p*p;++i){
		SEdev edev=prime_edevs[i];
		unsigned b;
		if(b=a*edev.i,b<=edev.t){
			int k=0;
			while(++k,a=b,b=a*edev.i,b<=edev.t);
			int n0=n*k;
			for(int j=0;j<n0;++j){
				divs[n++]=divs[j]*p;
			}
		}
	}
	if(a>1){
		int n0=n;
		for(int j=0;j<n0;++j){
			divs[n++]=divs[j]*a;
		}
	}
	return n;
}

int d[100000];

main(){
	mkprimes();
	mkedevs();

	char*rp=mmap(0l,1l<<28,1,2,0,0ll);
	char*wp=wbuf;

	rd_skip();
	while(*rp){
		int res=0;
		rd(x);
		rd(y);
		if(x==y){
			int nd=divisors(x,d);
			res+=x+(x&1)+nd-3;
		}else{
			if(x>y){
				int t=x;x=y;y=t;
			}
			int nd=divisors(y-x,d);
			rep(i,nd){
				int a=d[i]+1;
				int c=(y-x)/(a-1);
				if(x>c){
					int b=(x-c)/(a+1);
					c+=b;
					res+=a*b+c==x&&a*c+b==y;
				}
			}
		}
		wt(res);
		*wp++=10;
	}
	write(1,wbuf,wp-wbuf);
	_exit(0);
}
0