编程语言
首页 > 编程语言> > 洛谷题单 【数学】编程能力进阶

洛谷题单 【数学】编程能力进阶

作者:互联网

list


P1075 质因数分解

P1075

P1075.cpp

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int n;
int main(){
	scanf("%d",&n);
	for(int i=2;i<=sqrt(n);++i)
		if(n%i==0){
			printf("%d",n/i);
			return 0;
		}
}

P1888 三角函数

P1888

P1888.cpp

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[4],x;
int gcd(int x,int y){ return y==0 ? x : gcd(y,x%y); }
int main(){
	for(int i=1;i<=3;++i) scanf("%d",&a[i]);
	sort(a+1,a+1+3);
	x=gcd(a[1],a[3]);
	printf("%d/%d",a[1]/x,a[3]/x);
	return 0;
}

P6159 [Cnoi2020]光图

P6159

P6159

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define int long long
int n,p,k;
signed main(){
	scanf("%lld %lld %lld",&n,&p,&k);
	printf("%lld",p*k%n);
	return 0;
}

P6159_1


P2640 神秘磁石

P2640

P2640.cpp

#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int n,p[10010],k;
bool vis[10010],flog;
void getprime(){
	for(int i=2;i<=n;++i){
		if(!vis[i]) p[++p[0]]=i;
		for(int j=1;j<=p[0]&&i*p[j]<=n;++j){
			vis[i*p[j]]=1;
			if(i%p[j]==0) break;
		}
	}
}
int main(){
	scanf("%d %d",&n,&k);
	getprime();
	for(int i=1;i<=p[0]&&p[i]+k<=n;++i){
		if(!vis[p[i]+k]){
			flog=1;
			printf("%d %d\n",p[i],p[i]+k);
		}
	}
	if(!flog) printf("empty");
	return 0;
}

P5436 【XR-2】缘分

未完待续

标签:进阶,int,洛谷题,质数,编程,TAG,using,include,lld
来源: https://www.cnblogs.com/Potrem/p/LuoguQuestionsheet1.html