1 条题解
-
0
C++ :
#include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #define clr(x) memset(x,0,sizeof(x)) using namespace std; const int N=32000,SIZE=10000; bool check[N+10]; int prime[SIZE],tot; int a0_cnt[SIZE],a1_cnt[SIZE],b0_cnt[SIZE],b1_cnt[SIZE]; void euler() { for(int i=2;i<=N;i++) { if(!check[i])prime[tot++]=i; for(int j=0;j<tot;j++) { if(i*prime[j]>N)break; check[i*prime[j]]=1; if(i%prime[j]==0)break; } } } void divide(int num,int* cnt) { memset(cnt,0,sizeof(int)*SIZE); for(int i=0;i<tot;i++) while(num%prime[i]==0) { cnt[i]++; num/=prime[i]; } if(num!=1) { prime[tot]=num; cnt[tot++]=1; } } int n,a0,a1,b0,b1; int main() { euler(); scanf("%d",&n); while(n--) { scanf("%d%d%d%d",&a0,&a1,&b0,&b1); divide(a0,a0_cnt); divide(a1,a1_cnt); divide(b0,b0_cnt); divide(b1,b1_cnt); int x=1; for(int i=0;i<tot;i++) { int L,R,flag=2; if(a0_cnt[i]==a1_cnt[i])L=a0_cnt[i]; else flag--; if(b0_cnt[i]==b1_cnt[i])R=b0_cnt[i]; else flag--; if(flag==0&&a1_cnt[i]!=b1_cnt[i])x=0; if(flag==2)x*=R-L+1; } printf("%d\n",x); } return 0; }
Pascal :
program son; var p, x, c: array[1..10000] of longint; n, m, t, i, j, k, a0, a1, b0, b1: longint; function gcd(m, n: longint): longint; var r: longint; begin while n <> 0 do begin r := m mod n; m := n; n := r; end; gcd := m; end; procedure dfs(const i: longint; s: longint); var j: longint; begin if i > m then begin inc(k); p[k] := s; exit; end; dfs(i + 1, s); for j := 1 to c[i] do begin s := s * x[i]; dfs(i + 1, s); end; end; procedure get(b: longint); var i: longint; begin m := 0; i := 2; while i <= sqrt(b) + 1e-6 do begin if b mod i = 0 then begin inc(m); x[m] := i; c[m] := 0; repeat inc(c[m]); b := b div i; until b mod i <> 0; end; inc(i); end; if b <> 1 then begin inc(m); x[m] := b; c[m] := 1; end; k := 0; dfs(1, 1); end; begin read(n); for i := 1 to n do begin read(a0, a1, b0, b1); get(b1); t := 0; for j := 1 to k do if (gcd(p[j], a0) = a1) and (p[j] div gcd(p[j], b0) * b0 = b1) then inc(t); writeln(t); end; end.
- 1
信息
- ID
- 273
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者