結果

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

テストケース

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

int divisors(int a,int*divs){
	int n=0;
	divs[n++]=1;
	int i=0;
	int p;
	while(p=primes[i],a>=p*p){
		if(a%p==0){
			int k=1;
			while(a/=p,a%p==0){
				++k;
			}
			int n0=n*k;
			for(int j=0;j<n0;++j){
				divs[n++]=divs[j]*p;
			}
		}
		++i;
	}
	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();

	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);
				int b=(x-c)/(a+1);
				c+=b;
				res+=b>0&c>0&&a*b+c==x&&a*c+b==y;
			}
		}
		wt(res);
		*wp++=10;
	}
	write(1,wbuf,wp-wbuf);
	_exit(0);
}
0