luogu p1147 p1029

P1147 连续自然数和

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll sum[1000000];
int main(){
	ll n;
	cin>>n;
	for(int i=1;i<=1000000;++i){
		sum[i]=sum[i-1]+i;
	}
	int j=1;
	for(int i=2;i<=n/2+1;++i){
		for(;j<n/2+1;++j){
			ll temp=sum[i]-sum[j-1];
			if(temp==n)	cout<<j<<' '<<i<<endl;
			else if(temp<n)	break;
		}
	}
	return 0;
}

P1029 最大公约数和最小公倍数

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) {
	return b?gcd(b,a%b):a;
}
ll x,y;
int main() {
	cin>>x>>y;
	ll res=0;
	for(ll i=x; i<=y; i+=x) {
		for(ll j=i; j<=y; j+=x) {
			if(gcd(i,j)==x&&i*j/gcd(i,j)==y) {
				if(i!=j)	res+=2;
				else	res+=1;
			}
		}
	}
	cout<<res<<endl;
	return 0;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) {
	return b?gcd(b,a%b):a;
}
ll n,m,ans=0;
int main() {
	scanf("%lld%lld",&n,&m);
	for(int i=n; i<=m; i+=n)
		if((m*n)%i==0&&gcd(m*n/i,i)==n)
			ans++;
	printf("%lld",ans);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/TDD_Master/article/details/82946472