div3数论
有理数取余
1.首先转化形式,把除法形式转化为乘法的形式
2.费马小定理(记住结论即可)
3.通过费马小定理可以得出
4.注意a和b的范围,把字符串先转化为数字
代码:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N=1e6+10,mod=19260817,INF=1e17,M=5e6;
typedef pair<int,int> PII;
/*
233333
2
2*10+3=23
(2*10+3)*10+3=233
((2*10+3)*10+3)*10+3=2333
*/
int qmi(int a,int k){
int res=1;
while(k){
if(k&1) res=res*a%mod;
a=a*a%mod;
k>>=1;
}
return res;
}
void slove(){
string a,b;
cin>>a>>b;
int na=0,nb=0;
for(auto c:a){//遍历a的字符串,转化数字
na=(na*10+c-'0')%mod;
}
for(auto c:b) nb=(nb*10+c-'0')%mod;
cout<<na*qmi(nb,mod-2)%mod<<endl;
}
signed main(){
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
int T=1;
// cin>>T;
while(T--) slove();
}
codeforcesA
两数之间的差值是两个数的最大公约数的倍数(辗转相除法原理)
因为要求线段的端点的gcd为1,所以可以这样构造:
[1,2],[2,3],[3,4],[4,5]
这样一定是答案,若跨度区域大于2,例如[4,6],那么[4,5][5,6]就一定包含在这个线段里面,所以答案就是r-l
对于[1,1]要进行特殊判断
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N=1e6+10,mod=19260817,INF=1e17,M=5e6;
typedef pair<int,int> PII;
/*
233333
2
2*10+3=23
(2*10+3)*10+3=233
((2*10+3)*10+3)*10+3=2333
*/
int qmi(int a,int k){
int res=1;
while(k){
if(k&1) res=res*a%mod;
a=a*a%mod;
k>>=1;
}
return res;
}
/*
a b
如果说c=b-a
那么就说明c一定是b和a的最大公约数的倍数
a b,他们的最大公约数是d
那么一定就是说a+k*d=b
c=k*d;
1 10
1 2//差值为1,那么就一定是互质的
2 3
3 4
4 5
1,1
*/
void slove(){
int l,r;
cin>>l>>r;
if(l==1&&r==1){
cout<<1<<endl;
}else {
cout<<r-l<<endl;
}
}
signed main(){
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
int T=1;
cin>>T;
while(T--) slove();
}
素数密度
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N=1e6+10,mod=19260817,INF=1e17,M=5e6;
typedef pair<int,int> PII;
int qmi(int a,int k){
int res=1;
while(k){
if(k&1) res=res*a%mod;
a=a*a%mod;
k>>=1;
}
return res;
}
bool st[N];
void slove(){
int l,r;
cin>>l>>r;
for(int i=2;i<=100000;i++){//就是判断i在[l,r]区间内,有什么数是他的倍数就行了
//只对l,r进行筛
int k=(l+i-1)/i;
if(k==1) k++;//只筛i的倍数,并不包含i本身
for(int j=k*i;j<=r;j+=i) st[j-l+1]=true;//埃氏筛,并且把[l,r]转化为[1,r-l+1],把不是质数的打个标记
}
if(l==1) st[1]=true;
int ans=0;
for(int i=1;i<=r-l+1;i++)//统计答案
if(!st[i]) ans++;
cout<<ans<<endl;
}
signed main(){
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
int T=1;
// cin>>T;
while(T--) slove();
}
(最大公约数和最小公倍数问题)[https://www.luogu.com.cn/problem/P1029]
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N=1e6+10,mod=19260817,INF=1e17,M=5e6;
typedef pair<int,int> PII;
/*
233333
2
2*10+3=23
(2*10+3)*10+3=233
((2*10+3)*10+3)*10+3=2333
*/
int qmi(int a,int k){
int res=1;
while(k){
if(k&1) res=res*a%mod;
a=a*a%mod;
k>>=1;
}
return res;
}
int gcd(int a,int b){
return b?gcd(b,a%b):a;
}
bool st[N];
void slove(){
int x,y;
cin>>x>>y;
if(y%x!=0){//p,q的lcm=y,gcd=x,那么x一定是y的因子
cout<<0<<endl;
return ;
}
int p=y/x;
int ans=0;//记录答案
for(int i=1;i*i<=p;i++){
if(p%i==0){
int k1=i,k2=p/i;//p=k1*k2
if(gcd(k1,k2)==1){
ans++;
if(k1!=k2) ans++;//p,q不相等的,那么p,q可以互换,作为答案的贡献
}
}
}
cout<<ans<<endl;
}
signed main(){
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
int T=1;
// cin>>T;
while(T--) slove();
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架