互质数的个数(运用欧拉函数)
代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;//将long long类型定义为ll,使用ll来代替long long
typedef unsigned long long ull;
/*ull是unsigned long long的缩写,表示无符号长整型。在一些需要处理较大数值的情况下,使用无符号整型可以扩大数值范围。*/
#define ios ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
/*这行代码定义了一个宏 ios,将 ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) 替换为 ios。而 ios::sync_with_stdio(false) 表示取消 C++ 的输入输出流同步,cin.tie(0) 和 cout.tie(0) 分别表示将 cin 和 cout 与 nullptr(空指针)关联,即取消它们之间的关联,从而提高输入输出效率。*/
//const int N = 1e5+5;
const ll mod = 998244353;//const关键字用于定义常量。mod表示模数,可以防止意外修改它们的值。
ll a, b;//ll a, b;定义了两个long long类型的变量a和b
ll phi(ll n)//用于计算欧拉函数的值
{
ll res = n;
for(int i = 2; i * i <= n; i++)
{
if(n % i == 0)
{
res = res/i*(i - 1);
while(n % i == 0) n /= i;
}
}
if(n > 1) res = res/n*(n - 1);
return res;
}
ll qpow(ll a, ll b)
{
ll res = 1;
while(b)
{
if(b & 1) res = res * a % mod;
a = a*a%mod;
b >>= 1;
}
return res;
}
void solve()
{
cin >> a >> b;
ll ans = phi(a);
ans = ans*qpow(a, b - 1)%mod;
cout << ans << endl;
}
int main()
{
ios;
solve();
return 0;
}
错误票据
注意点:并没有给出输入数据的个数
代码
#define LL long long
#define end1 '\n'
#define PII pair<int,int>
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
const LL N=2e5+10,M=1e3+10;
LL a[N];
signed main()
{
ios::sync_with_stdio(0),cin.tie(0);
int n;
cin>>n;
int cnt=0;
while(cin>>a[++cnt]);//在循环之前就加一,从a[1]开始存,cnt==数据个数+1
//循环结束时,cnt的值会比实际输入的元素数量大1。
int ans1,ans2;
sort(a+1,a+cnt);//从小到大排列
//数组a的索引是从1开始使用的,目的是为了让数组的索引与实际的数学模型对齐
//a+1表示指向数组a第二个元素(a[1])的指针。
//a+cnt是因为!!sort函数的第二个参数是指向要排序范围末尾的下一个位置的指针!!
//在C++中,排序范围是左闭右开的,所以需要加1来包含最后一个元素。
for(int i=1;i<cnt;i++)
{
if(a[i]==a[i+1])
{
ans1=a[i];
}
if(a[i]==a[i+1]-2)
{
ans2=a[i]+1;
}
}
cout<<ans2<<" "<<ans1<<end1;
return 0;
}
特殊年份
代码
#define LL long long
#define end1 '\n'
#define PII pair<int,int>
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
const LL N=2e5+10,M=1e3+10,mod=998244353;
LL a[N];
signed main()
{
ios::sync_with_stdio(0),cin.tie(0);
int n=5;
int cnt=0;
for(int i=1;i<=5;i++)
{
string s;
cin>>s;
if(s[0]==s[2]&&s[3]-s[1]==1)
//std::string类重载了operator[],允许你像访问数组元素一样访问字符串中的每个字符。
cnt++;
}
cout<<cnt<<end1;
return 0;
}
小平方
注意点:n为奇数和偶数要分开讨论
代码
#define LL long long
#define end1 '\n'
#define PII pair<int,int>
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
const LL N=2e5+10,M=1e3+10,mod=998244353;
LL a[N];
signed main()
{
ios::sync_with_stdio(0),cin.tie(0);
int n;
int cnt=0;
cin>>n;
for(int i=1.0;i<n;i++)
{
if(n%2==1&&(i*i%n)<=(n-1)/2)
cnt++;
if(n%2==0&&(i*i%n)<n/2)
cnt++;
}
cout<<cnt<<end1;
return 0;
}
冶炼金属
考点:数学思想,自己找规律
注意点:因为转换率需要对所有样例都成立,所以求完最大值之后需要取较小的那个数,求完最小值之后需要取教大的那个数。不懂的话自己可以多举几个例子就会了。多思考
代码
#include <iostream>
#include <bits/stdc++.h>
#define int long long
#define PII pair<int,int>
#define endl '\n'
#define LL __int128
using namespace std;
const int N=2e5+10,M=1e3+10,mod=998244353,INF=0x3f3f3f3f;
int mx=1e18,mi=-1e18;
signed main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n,i=0;
cin>>n;
while(n--)
{
int a,b;
cin>>a>>b;
mx=min(mx,a/b);//最大值要取最小,最小值要取最大.多想想对比一下就懂了
mi=max(mi,a/(b+1)+1);
}
cout<<mi<<' '<<mx<<endl;
return 0;
}
子2023
考点:动态规划
此题为填空题,直接提交答案即可
代码
/*
动态数组有后效性
f[0]就是长度为1的字符串的数量,题目中为2
f[1]就是长度为2的字符串的数量,题目中为20
f[2]就是长度为3的字符串的数量,题目中为202
f[3]就是长度为4的字符串,题目中为2023
f[0]会影响f[1],f[1]会影响f[2]
写法:f[i]由什么转移过来
初始化:根据题目意思
*/
#include <iostream>
#include <bits/stdc++.h>
#define endl '\n'
#define PII pair<int,int>
#define int long long
#define LL __int128
const int N=2E5+10,M=1E3+10,mod=998244353,INF=0x3f3f3f3f;
using namespace std;
int a[N],pre[N];
int f[N];
signed main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
string s;
for(int i=1;i<=2023;i++)
{
s+=to_string(i);//将整数转化为字符串
}
for(int i=0;i<s.size();i++)
{
if(s[i]=='2') f[0]++,f[2]+=f[1];//因为两个位置有2,原来就有的数量加上新形成的数量
if(s[i]=='0') f[1]+=f[0];
if(s[i]=='3') f[3]+=f[2];
}
cout<<f[3]<<endl;
return 0;
}