数学3
我们先复习,再预习,最后写题
1.两点之间的距离公式:
2.海伦公式 若三角形的边长为a,b,c,则三角形的面积是
s=
3.小数保留整数
直接cout,会使用科学计数法
整数部分超过6位会采用科学计数法
4.异或
偶数次相同的数字异或,答案是0
a ^ a=0
奇数次相同的数字异或,答案是数字本身
a ^ a ^ a=0 ^a=a
异或规则:相同的位都是1,或都是0的时候,答案为0
0异或任何数都等于原数字
5.幂次方
6.唯一分解定理
给定一个大于1的正整数n,一定可以为已拆分为若干个质因子相乘
如果d|n(整除符号:代表n%d==0)
n能够唯一分解
d能够唯一分解
①n的质因子,一定包含d的质因子种类
②n的对应的质因子幂次大于等于d的质因子幂次
7.奇偶性
.
.
如果l和r的奇偶性相同:
①r-l+1一定是奇数
②r+1一定是偶数
如果l和r的奇偶性不同:
①r-l+1一定是偶数
②r+1一定是奇数
8. 斐波那契数列(肥不垃圾数列)
数列结构:奇 偶 偶 奇 偶 偶 奇 偶 偶 奇 偶 偶\cdots
接下来是plus知识
今日知识
1.lcm(x,y)最小公倍数与gcd(x,y)最大公约数
lcm(a,b)=a/gcd(x,y)*b;
互质的定义:两个数字的gcd为1,没有公共因子
任意两个大于等于1的数字互质
2.一次函数
x,y总是能连成一条线
3.prime
思路:
如果一个数是质数,那么把他的倍数的数字标记,没标记的都是质数
开始写题(一共9道,别问我为什么)
1 ----------- F1085 因子求和
用一个循环求
#include<bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int TWO=1005;
const int ONE=1000005;
const int im=INT_MAX;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,ans=0;
cin>>n;
for(int i=1;i*i<=n;i++){
if(n%i==0){
ans+=i;
if(n/i==i){
ans-=i;
}
ans+=n/i;
}
}
cout<<ans-1-n;
return 0;
}
2 ----------- P1403 [AHOI2005] 约数研究
用一个循环求,n中有n/x个是x的倍数的数
#include<bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int TWO=1005;
const int ONE=1000005;
const int im=INT_MAX;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,ans=0;
cin>>n;
for(int i=1;i<=n;i++){
ans+=n/i;
}
cout<<ans;
return 0;
}
3 ----------- P5436 【XR-2】缘分
根据任意两个大于等于1的数字互质的性质写(别问我怎么推的)
#include<bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int TWO=1005;
const int ONE=1000005;
const int im=INT_MAX;
void work(){
int n;
cin>>n;
if(n==1){
cout<<"1\n";
}else{
cout<<n*(n-1)<<"\n";
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
work();
}
return 0;
}
4 ----------- B3698 [语言月赛202301] 一次函数
不会的没看预习
#include<bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int TWO=1005;
const int ONE=1000005;
const int im=INT_MAX;
int ans;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,k,b;
cin>>n>>k>>b;
for(int i=1;i<=n;i++){
int x,y;
cin>>x>>y;
if(y==k*x+b){
ans++;
}
}
cout<<ans;
return 0;
}
5 ----------- P5736 【深基7.例2】质数筛
模板
#include<bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int TWO=1005;
const int ONE=1000005;
const int im=INT_MAX;
bool v[1000005];
int a[1000005];
void prime(int n){
v[0]=v[1]=1;
for(int i=1;i<=n/i;i++){
if(v[i]==0){
for(int j=i*2;j<=n;j+=i){
v[j]=1;
}
}
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,maxn=-1e9;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
maxn=max(maxn,a[i]);
}
prime(maxn);
for(int i=1;i<=n;i++){
if(v[a[i]]==0){
cout<<a[i]<<" ";
}
}
return 0;
}
6 ----------- B3969 [GESP202403 五级] B-smooth 数
改进
#include<bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int TWO=1005;
const int ONE=1000005;
const int im=INT_MAX;
int v[1000005];
int a[1000005];
void prime(int n){
v[1]=1;
for(int i=2;i<=n;i++){
if(v[i]==0){
for(int j=i;j<=n;j+=i){
v[j]=i;
}
}
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,b,ans=0;
cin>>n>>b;
prime(n);
for(int i=1;i<=n;i++){
if(v[i]<=b){
ans++;
}
}
cout<<ans;
return 0;
}
7 ----------- P6421 [COCI2008-2009#2] RESETO
简单质数筛
#include<bits/stdc++.h>
#include <iostream>
#include <string>
//#pragma GCC optimize(2)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int TWO=1005;
const int ONE=1000005;
bool f[ONE];
int main(){
//freopen("as01.in","r",stdin);
//freopen("as01.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,k;
cin>>n>>k;
for(int i=2;i<=n;i++){
if(f[i]==0){
for(int j=i;j<=n;j+=i){
if(f[j]==1){
continue;
}
k--;
if(k==0){
cout<<j;
return 0;
}
f[j]=1;
}
}
}
return 0;
}
``