193 条题解
-
-1杨哲焓 LV 4 @ 2016-11-11 07:54:40
评测结果
编译成功Free Pascal Compiler version 3.0.0 [2015/11/16] for i386
Copyright (c) 1993-2015 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling foo.pas
foo.pas(16,50) Warning: Variable "ans" does not seem to be initialized
Linking foo.exe
17 lines compiled, 0.0 sec, 27680 bytes code, 1268 bytes data
1 warning(s) issued
测试数据 #0: Accepted, time = 0 ms, mem = 808 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 808 KiB, score = 10
测试数据 #2: Accepted, time = 46 ms, mem = 804 KiB, score = 10
测试数据 #3: TimeLimitExceeded, time = 1015 ms, mem = 808 KiB, score = 0
测试数据 #4: Accepted, time = 62 ms, mem = 812 KiB, score = 10
TimeLimitExceeded, time = 1123 ms, mem = 812 KiB, score = 40pascal
var n,m,ans,i,j:longint;
function gcd(a,b:longint):longint;
begin
if b=0 then exit(a);
if a<b then exit(gcd(a,b mod a))
else exit(gcd(b,a mod b));
end;
function lcm(a,b:longint):longint;
begin
exit(a*b div gcd(a,b));
end;
begin
readln(n,m);
for i:=1 to n*m div gcd(n,m) do
for j:=1 to n*m div gcd(n,m) do
if (gcd(i,j)=n) and (lcm(i,j)=m) then inc(ans);
write(ans);
end.
请大牛帮帮忙!为啥只有40分? -
-12016-10-05 21:38:28@
评测结果
编译成功测试数据 #0: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 556 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 564 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 560 KiB, score = 10
Accepted, time = 0 ms, mem = 564 KiB, score = 50#include <iostream>
using namespace std;int64 gcd(int64 a, __int64 b)
{
__int64 temp;
while(b)
{
temp = b;
b = a % b;
a = temp;
}return a;
}int64 lcm(int64 a,__int64 b)
{
return (a*b/gcd(a,b));
}int main()
{
__int64 a,b;
int iCnt = 0;
cin >> a >> b;int64 iMul = a*b;
for(int64 i=a;i<=b;i+=a){if (gcd(i,iMul/i)==a && lcm(i,iMul/i)==b){
iCnt++;
}
}
cout << iCnt;
return 0;
} -
-12016-09-08 20:54:33@
water
var
n,m,k,i,total:longint;
function gcd(a,b:longint):boolean;
var r:longint;
begin
repeat
r:=a mod b;
a:=b;
b:=r;
until b=0;
if a=n then exit(true)
else exit(false);
end;
begin
total:=0;
readln(n,m);
k:=n*m;
for i:=n to trunc(sqrt(k)) do begin
if (k mod i=0) and gcd(i,k div i) then inc(total);
end;
writeln(total*2);
end. -
-12016-09-07 21:45:56@
评测结果 编译成功 测试数据 #0: Accepted, time = 0 ms, mem = 556 KiB, score = 10 测试数据 #1: Accepted, time = 0 ms, mem = 556 KiB, score = 10 测试数据 #2: Accepted, time = 0 ms, mem = 556 KiB, score = 10 测试数据 #3: Accepted, time = 15 ms, mem = 560 KiB, score = 10 测试数据 #4: Accepted, time = 0 ms, mem = 556 KiB, score = 10 Accepted, time = 15 ms, mem = 560 KiB, score = 50 代码 #include <iostream> using namespace std; inline int gcd(int a,int b) { if (a%b) return gcd(b,a%b); else return b; } int main (){ ios :: sync_with_stdio(false); int x,y,ans = 0; cin >> x >> y; for (int i = 1;i <= y;i++) for (int j = 1;i*j <= x*y;j++) if (gcd(i,j) == x && i*j == x*y) ans++; cout << ans; return 0; }
-
-12016-07-16 21:46:06@
var x,y,i,s,a:int64;
function pd(a,b:int64):boolean;
var
tmp:int64;
i,j:longint;
begin
tmp:=0;
while b>0 do
begin
tmp:=b;
b:=a mod b;
a:=tmp;
end;
pd:=false;
if tmp=x then pd:=true;
end;begin
read (x,y);
i:=1;
s:=0;
while i< (x*y) do
begin
a:=x*y div i;
if pd(a,i) and (a*i=x*y) then
inc(s);
inc(i);
end;
write(s);
end. -
-12016-07-16 21:07:48@
var
p,q,n,i,j,num:longint;
a,b,w:int64;
function pd(a,b:int64):boolean;
var
tmp:int64;
i,j:longint;
begin
tmp:=0;
while b>0 do
begin
tmp:=b;
b:=a mod b;
a:=tmp;
end;
pd:=false;
if tmp=p then pd:=true;
end;
begin
readln(p,q);
if p=q then
begin
writeln('1');
exit;
end;
n:=q div p;
w:=q*p;
num:=0;
for i:=1 to n do
begin
a:=i*p;
if (w mod a=0) {and ((w div a) div p=0)} and (pd(a,w div a)) then inc(num);
end;
writeln(num);
end. -
-12016-07-16 10:18:42@
#include <cstdio>
int gcdlight(int a,int b){
return b==0?a:gcdlight(b,a%b);
}int main(){
//freopen("in.txt","r",stdin);
int x,y,count=0;
scanf("%d%d",&x,&y);
int w=x*y,k;for(int i=2;i<=w;i++){
if(!(w%i)==0)
continue;
k=w/i;
if(gcdlight(k,i)==x)
count++;
}
printf("%d",count);
return 0;
} -
-12016-05-16 19:12:00@
include <stdio.h>
int gcd(int m, int n)
{
return n == 0 ? m : gcd(n,m%n);
}int main (void)
{
int x, y, cnt, m;
scanf("%d%d",&x,&y);
for (m=1, cnt=0; m<=y; m++) {
if (y % m == 0 && gcd(m*x,y/m) == x) {
cnt++;
}
}
printf("%d\n",cnt);
return 0;
} -
-12016-03-27 20:18:37@
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>using namespace std;
int main()
{
int x0, y0;
cin >> x0 >> y0;if (y0 % x0 != 0)
{
cout << 0;
return 0;
}y0 /= x0;
int ans = 1;
for (int i = 2; i * i <= y0; ++i)
if (y0 % i == 0)
{
while (y0 % i == 0)
y0 /= i;
ans *= 2;
}
if (y0 != 1)
ans *= 2;cout << ans << endl;
return 0;
}相当于求y0/x0的互质分解个数,也就是2^(它的质因数种数)。
-
-12016-02-21 12:52:41@
/* *********************************************** Author :guanjun Created Time :2016/2/21 12:34:37 File Name :vijosp1131.cpp ************************************************ */ #include <iostream> #include <cstring> #include <cstdlib> #include <stdio.h> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <iomanip> #include <list> #include <deque> #include <stack> #define ull unsigned long long #define ll long long #define mod 90001 #define INF 0x3f3f3f3f #define maxn 10000+10 #define cle(a) memset(a,0,sizeof(a)) const ull inf = 1LL << 61; const double eps=1e-5; using namespace std; priority_queue<int,vector<int>,greater<int> >pq; struct Node{ int x,y; }; struct cmp{ bool operator()(Node a,Node b){ if(a.x==b.x) return a.y> b.y; return a.x>b.x; } }; bool cmp(int a,int b){ return a>b; } ll gcd(ll a,ll b){ return a==0?b:gcd(b%a,a); } int main() { #ifndef ONLINE_JUDGE //freopen("in.txt","r",stdin); #endif //freopen("out.txt","w",stdout); ll x,y; while(cin>>x>>y){ ll z=x*y; ll ans=0; for(int i=x;i<=y;i+=x){ if(y%i==0) if(gcd(i,(z/i))==x)ans++; } cout<<ans<<endl; } return 0; }
-
-12015-12-14 10:31:07@
#include <stdio.h>
const int primeCount=9592;
int prime[primeCount]=
{
//WARNING
//此处略,表太长自己打,或者临时计算
};int PrimeDivisors(int test)
{
int ret=0;
for(int i=0;i<primeCount&&prime[i]<=test;i++)
{
if(test%prime[i]==0)
{
while(test%prime[i]==0)
{
test/=prime[i];
}
ret++;
}
}
return ret;
}int main()
{
int x,y;
int index;
scanf("%d%d",&x,&y);
if(y%x!=0)
{
printf("0\n");
return 0;
}
index = PrimeDivisors(y/x);
int ans=1;
for(int i=0;i<index;i++)
{
ans*=2;
}
printf("%d\n",ans);
return 0;
} -
-12015-11-05 14:10:22@
#include<iostream>
#include<cstring>
using namespace std;int p[12]={2,3,5,7,11,13,17,19,23,29,31,37};
int b[12][2];
int count=0;void k(int a){
for(int i=0;i<=11;i++){
while(a%p[i]==0){
a=a/p[i];
b[i][count]++;
}
}
return;
}int main(){
int x,y;
int ans=1;
cin>>x>>y;
memset(b,0,sizeof(b));
if(y%x!=0) { cout<<"0"; return 0; }
k(x); count++; k(y);
for(int i=0;i<=11;i++){
b[i][1]=b[i][1]-b[i][0];
}
for(int i=0;i<=11;i++){
if(b[i][1]!=0) ans=ans*2;
}
cout<<ans;
return 0;
} -
-12015-10-31 20:04:23@
数据太弱。
/*
ID:
LANG:
TESK:
*/
#include <iostream>
#include <fstream>
//#include <cstdio>
//#include <cstdlib>
//#include <string>
//#include <cstring>
//#include <cmath>
//#include <algorithm>
using namespace std;
typedef long long longint;
const string file_name = "p1131";
const string file_in_name = file_name+"in";
const string file_out_name = file_name+".out";
const int N=100;
longint x0,y0,m,p,q,s=0;
int swap(longint &x,longint &y)
{
x = x ^ y;
y = x ^ y;
x = x ^ y;
return 0;
}
longint gcd(longint x,longint y)
{
while(y!=0){
x = x % y;
swap(x,y);
}
return x;
}
int main()
{
//ifstream cin(file_in_name.c_str(),ios::in);
//ofstream cout(file_out_name.c_str(),ios::out);
//freopen(file_in_name.c_str(),"r",stdin);
// freopen(file_out_name.c_str(),"w",stdout);
cin>>x0>>y0;
m=x0*y0;
for(p=x0;p<=y0;p+=x0){
q=m/p;
longint t=gcd(p,q);
if(t==x0&&p*q/t==y0)/*cout<<p<<' '<<q<<endl,*/s++;
}
cout<<s;
//cin.close();
//cout.close();
return 0;
} -
-12015-10-26 19:20:34@
楼下的那个代码多计算了一次gcd
ans+=(gcd(p,q)==x0)&&(lcm(p,q)==y0);
这个位置的可以先计算gcd,然后利用p*q/gcd求出lcm,效率略高
编译成功测试数据 #0: Accepted, time = 0 ms, mem = 520 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 524 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 520 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 524 KiB, score = 10
测试数据 #4: Accepted, time = 3 ms, mem = 524 KiB, score = 10
Accepted, time = 3 ms, mem = 524 KiB, score = 50
代码
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <functional>
#include <cmath>
using namespace std;
int gcd(int a, int b)
{
if (b == 0)
{
return a;
}
return gcd(b, a%b);
}
int main()
{
int x, y;
int p, q;
int g;
int ans;
ans = 0;
cin >> x >> y;
for (p = x; p <= y; p++)
{
q = (y / p)*x;
g = gcd(p, q);
if ((g == x) && (p*q / g) == y)
{
ans++;
}
}
cout << ans << endl;
return 0;
} -
-12015-10-26 11:03:27@
正确的时间复杂度的算法
由题意得,gcd(p,q)=x0 lcm(p,q)=y0
显然p的一个约数为x0 我们选择在区间[x0,y0]之间枚举p
当p确定后,我们由 lcm(p,q)=p*q/gcd(p,q)=y0 可以算出q=y0/(p/x0)
现在p,q都已经确定了 直接判定就好了
复杂度O(N*logN) 枚举O(N) gcd是log的
###Block code#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<bitset>
#include<map>
#include<bitset>
using namespace std;
int ans,x0,y0;
long long gcd(long long a,long long b)
{return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b)
{return a/gcd(a,b)*b;}
int main()
{
scanf("%d%d",&x0,&y0);
for(int i=x0;i<=y0;i+=x0)
{
long long p=i;
long long q=y0/(p/x0);
ans+=(gcd(p,q)==x0)&&(lcm(p,q)==y0);
}
cout<<ans<<endl;
} -
-12015-08-21 09:11:16@
额呵呵,直接暴力过了……0ms
#include<cstdio>
#include<algorithm>
using namespace std;int gcd(int x,int y){
if (y==0) return x;else return gcd(y,x%y);
}
int n,m,ans=0;
int main(){
scanf("%d%d",&n,&m);
for (int i=n;i<=m;i+=n)
if (m%i==0)
for (int j=i;j<=m;j+=n)
if (m%j==0)
if (gcd(m/i,m/j)==1){
if (gcd(i/n,j/n)==1) ans++;
}
printf("%d\n",ans*2);
} -
-12015-08-06 10:28:25@
#include<cstdio>
using namespace std;
int gcd(int a,int b)
{
if(a==0)return b;
else return gcd(b%a,a);
}
int lcm(int a,int b)
{
return a*b/gcd(a,b);
}
int main()
{
int j,i,a,b,ans=0,cnt=0,tt=0,kk=0;
scanf("%d%d",&a,&b);
for(i=a;i<=b;i+=a)
{
for(j=a;j<=b;j+=a)
{
if(gcd(i,j)==a && lcm(i,j)==b)
{
ans++;
}
}
}
printf("%d",ans);
return 0;
} -
-12015-08-06 10:16:04@
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
int mymax(int x,int y)
{
return x>y?x:y;
}
int gcd(int a,int b)
{
if(a%b==0)
{
return b;
}
else
{
return gcd(b,a%b);
}
}
int gcdb(int a,int b)
{
return a/gcd(a,b)*b;
}
int main()
{
int x,y,len,ans;
scanf("%d%d",&x,&y);
ans=0;
for(int i=1;i<=y;i++)
{
for(int j=i;j<=y;j++)
{
if(i%x!=0)
{
break;
}
if(y%i!=0)
{
break;
}
if(j%x==0 && y%j==0)
{
if(gcd(j,i)==x && gcdb(j,i)==y)
{
if(i==j)
{
ans++;
}
else
{
ans+=2;
}
}
}
}
}
printf("%d\n",ans);
return 0;
}
改了一点点东西 -
-12015-08-06 10:11:56@
水题,很简单
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
int mymax(int x,int y)
{
return x>y?x:y;
}
int gcd(int a,int b)
{
if(a%b==0)
{
return b;
}
else
{
return gcd(b,a%b);
}
}
int gcdb(int a,int b)
{
return a/gcd(a,b)*b;
}
int main()
{
int x,y,len,ans;
scanf("%d%d",&x,&y);
len=mymax(x,y);
ans=0;
for(int i=1;i<=len;i++)
{
for(int j=i;j<=len;j++)
{
if(i%x!=0)
{
break;
}
if(y%i!=0)
{
break;
}
if(j%x==0 && y%j==0)
{
if(gcd(j,i)==x && gcdb(j,i)==y)
{
if(i==j)
{
ans++;
}
else
{
ans+=2;
}
}
}
}
}
printf("%d\n",ans);
return 0;
} -
-12015-06-07 11:24:59@
//先说一下思路吧:其实我的程序理论上应该是215错误或者tle的但是不知道是不是数据给的*太弱了*
就秒杀了……
1.先令num=x*y(若两数互质时的最小公倍数,即最坏情况下的最小公倍数)
2.将num拆分成两个数
3.检验这两个数是否符合条件,符合就计数器+1
4.输出时计数器*2(因为一个数就对应着两个数)
本来只想骗分的,但是没想到ac了……代码
BLOCK code
var
i:Longint;
x,y,total,tmp,num:longint;
function gcd(a,b:int64):int64;
begin
if b=0 then exit(a) else exit(gcd(b,a mod b));
end;
begin
readln(x,y);
if x=y then begin writeln(x); exit; end;
num:=x*y;
for i:=1 to trunc(sqrt(num)) do
begin
if num mod i=0 then
begin
tmp:=gcd(i,num div i);
if (tmp=x) and (num div tmp=y) then inc(total);
end;
end;writeln(total*2);
end.block code
评测结果
编译成功Free Pascal Compiler version 2.6.4 [2014/03/06] for i386
Copyright (c) 1993-2014 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling foo.pas
foo.pas(17,56) Warning: Variable "total" does not seem to be initialized
Linking foo.exe
21 lines compiled, 0.1 sec , 28544 bytes code, 1628 bytes data
1 warning(s) issued
测试数据 #0: Accepted, time = 0 ms, mem = 768 KiB, score = 10
测试数据 #1: Accepted, time = 2 ms, mem = 768 KiB, score = 10
测试数据 #2: Accepted, time = 1 ms, mem = 772 KiB, score = 10
测试数据 #3: Accepted, time = 1 ms, mem = 768 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 768 KiB, score = 10
Accepted, time = 4 ms, mem = 772 KiB, score = 50