当前位置:网站首页>Acwing第 59 场周赛(AK)
Acwing第 59 场周赛(AK)
2022-07-17 05:13:00 【lovesickman】
4492. 减法操作
给定一个整数 n n n,执行如下算法:
- 如果 n = 0 n=0 n=0,则结束算法。
- 找到 n n n 的最小质因子 d d d。
- 令 n n n 减去 d d d 并跳转步骤 1 1 1。
请你计算,在算法执行的过程中,一共进行了多少次减法操作。
输入格式
一个整数 n n n。
输出格式
一个整数,表示减法操作的次数。
数据范围
所有测试点满足 2 ≤ n ≤ 1 0 10 2≤n≤10^{10} 2≤n≤1010
/* A: 10min B: 20min C: 30min D: 40min */
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <assert.h>
#include <sstream>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mem(f, x) memset(f,x,sizeof(f))
#define fo(i,a,n) for(int i=(a);i<=(n);++i)
#define fo_(i,a,n) for(int i=(a);i<(n);++i)
#define debug(x) cout<<#x<<":"<<x<<endl;
#define endl '\n'
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
template<typename T>
ostream& operator<<(ostream& os,const vector<T>&v){
for(int i=0,j=0;i<v.size();i++,j++)if(j>=5){
j=0;puts("");}else os<<v[i]<<" ";return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>&v){
for(auto c:v)os<<c<<" ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>&v){
for(auto c:v)os<<c.first<<" "<<c.second<<endl;return os;}
template<typename T>inline void rd(T &a) {
char c = getchar(); T x = 0, f = 1; while (!isdigit(c)) {
if (c == '-')f = -1; c = getchar();}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + c - '0'; c = getchar();} a = f * x;
}
typedef pair<long long ,long long >PII;
typedef pair<long,long>PLL;
typedef long long ll;
typedef unsigned long long ull;
const int N=2e5+10,M=1e9+7;
ll n,cnt;
// 判断n是不是质数
bool is_prime(ll n) {
if (n == 1) return false;
for (ll i = 2; i * i <= n; i++) {
if (n % i == 0) return false;
}
return true;
}
void solve(){
cin>>n;
if(!is_prime(n)){
if(n&1){
// 求n的最小质因子
ll x=n;
ll i;
for( i=2;i*i<=x;i++){
if(x%i==0){
break;
}
}
cout<<1+(x-i)/2<<endl;
}
else
cout<<n/2;
}
else{
cout<<1;
}
}
int main(){
solve();
return 0;
}
4493. 环形连通分量
并查集水题,题意模拟就行
/* A: 10min B: 20min C: 30min D: 40min */
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <assert.h>
#include <sstream>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mem(f, x) memset(f,x,sizeof(f))
#define fo(i,a,n) for(int i=(a);i<=(n);++i)
#define fo_(i,a,n) for(int i=(a);i<(n);++i)
#define debug(x) cout<<#x<<":"<<x<<endl;
#define endl '\n'
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
template<typename T>
ostream& operator<<(ostream& os,const vector<T>&v){
for(int i=0,j=0;i<v.size();i++,j++)if(j>=5){
j=0;puts("");}else os<<v[i]<<" ";return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>&v){
for(auto c:v)os<<c<<" ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>&v){
for(auto c:v)os<<c.first<<" "<<c.second<<endl;return os;}
template<typename T>inline void rd(T &a) {
char c = getchar(); T x = 0, f = 1; while (!isdigit(c)) {
if (c == '-')f = -1; c = getchar();}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + c - '0'; c = getchar();} a = f * x;
}
typedef pair<long long ,long long >PII;
typedef pair<long,long>PLL;
typedef long long ll;
typedef unsigned long long ull;
const int N=4e5+10,M=1e9+7;
int n,m;
int h[N],e[N],ne[N],idx;
int cnt;
vector<int>g[N];
int fa[N];
void add(int a,int b){
e[idx]=b;
ne[idx]=h[a];
h[a]=idx++;
}
int find(int u){
return fa[u]==u?u:fa[u]=find(fa[u]);
}
void merge(int u,int v){
int fu=find(u),fv=find(v);
if(fu==fv)return;
fa[fu]=fv;
}
int d[N];
void solve(){
cin>>n>>m;
memset(h,-1,sizeof(h));
fo(i,1,n)fa[i]=i;
fo(i,1,m){
int u,v;cin>>u>>v;
add(u,v);add(v,u);
d[u]++;
d[v]++;
merge(u,v);
}
fo(i,1,n){
g[find(i)].pb(i);
}
// fo(i,1,n){
// cout<<i<<" "<<g[i].size()<<endl;
// }
for(int i=1;i<=n;i++){
if(g[i].size()>=3){
bool flag=1;
for(auto c:g[i]){
if(d[c]!=2){
flag=0;
break;
}
}
if(flag){
cnt++;
}
}
}
cout<<cnt<<endl;
}
int main(){
solve();
return 0;
}
边栏推荐
- 比例阀放大板1A、2A、3A、5A比例阀驱动模块0-10V转0-24V
- 压力应变桥信号处理光电隔离放大器
- Vscode configuring golang development environment
- 4-20mA to 0-5khz, 5V pulse converter
- MySQL workbench basically uses [create a database]
- 转速传感器信号隔离、采集及变换,正弦波、锯齿波信号输入,方波信号输出,信号转换器
- HM agent multi section lithium battery charging IC
- HM8203线性两串充电管理控制器IC
- LTH7五脚芯片的完整方案图FS4054充电电路原理
- RS-485/232转4-20mA/0-10V隔离D/A转换器
猜你喜欢

【简单快速】启动后桌面正常下方任务栏无反应/鼠标一直转圈

热电阻pt100 CU50隔离转换器转4-20ma模拟量输出温度变送器0-10V

Hra2460d-2w high voltage power supply high voltage module - high voltage - high precision hra2460d-2w

配置VsCode中‘log’快捷键去掉console.log(‘‘);中的分号;

IT4058A型号单节锂离子电池充电管理

EasyDarawin流媒体服务器介绍

MySQL Workbench基本使用【创建一个数据库】

Configure the 'log' shortcut key in vscode and remove the console log(‘‘); Semicolon in;
![MySQL workbench basically uses [create a data table]](/img/cf/00818451ef0e8bcd5cc1d12f00d27c.png)
MySQL workbench basically uses [create a data table]

golang 多项目工作区搭建
随机推荐
uboot 编译前的配置命令make config分析
Review of software process and management (10)
2022-7-15 廉价国产PLC工控板带485主从通信的零散记录
2021 - 09 - 15
4-20ma转4-20ma 0-5v转0-5v 模拟信号隔离变送器
Conversion, isolation and transmission of international standard signals 0-5v/0-10v/1-5v, 0-10ma/0-20ma/4-20ma, etc
模拟信号深入讨论4-20mA电流信号的传输距离
HRA isolation series wide voltage input positive and negative high voltage regulated output
低功耗LDO线性稳压IC
MEX and Increments
升压DC/DC转换器
FS5383A锂电池3.7V输入供电太阳能草坪灯驱动IC
MySQL workbench basically uses [create a database]
2021-09-15
【简单快速】启动后桌面正常下方任务栏无反应/鼠标一直转圈
HM8203线性两串充电管理控制器IC
MySQL Workbench基本使用 【创建一个数据表】
RestAPI实现聚合(黑马教程)
串口循环缓存区 简单 免初始化 不用堆、指针、分段memcpy
有线电视网(树上分组)