CodeForces-1076B Divisor Subtraction 找规律
题目链接:https://vjudge.net/problem/CodeForces-1076B
题意:
题目要求给定一个数,要求每次减去其最小素因数(既是素数又是其因数),问直到n=0需要做几次运算。
分析:
首先如果n为素数,则其最小素因数就是它本身,故第一次运算n:=n-n即得0,只需要一次运算。当n为偶数时,素因子恒为2,故每次减2直到0,所以运算次数为n/2次,当n为奇数是,首先减一次最小素因子,因为最小素因子一定是奇数,故奇-奇=偶,变为偶数后就按上述做法求得运算次数即可。
总结如下:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
typedef long long ll;
using namespace std;
ll n; bool prime(ll x) {
for(ll i = ; i <= sqrt(x); i++) {
if(x % i == )
return false;
}
return true;
} ll min_div(ll x) {
for(ll i = ; i < n; i++) {
if(x % i == )
return i;
}
} int main(void) {
while(scanf("%lld", &n) == ) {
if(prime(n)) {
printf("1\n");
continue;
}
else if(n % == ) {
printf("%lld\n", n/);
continue;
}
else {
n -= min_div(n);
printf("%lld\n", n/+);
}
}
}
CodeForces-1076B Divisor Subtraction 找规律的更多相关文章
- Lieges of Legendre CodeForces - 603C (博弈论,SG找规律)
大意: 给定$n$堆石子, 两人轮流操作, 每次操作两种选择 $(1)$任选非空堆拿走一个石子 $(2)$任选石子数为$2x(x>0)$的一堆, 替换为$k$堆$x$个石子. ($k$给定) 最 ...
- codeforces 615E Hexagons (二分+找规律)
E. Hexagons time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- codeforces 353D 递推 找规律
题意:一组男生女生在排队,每秒钟所有排在女生左边的男生与她相邻的女生交换位置,求女生全部换到男生前面的时间. 思路: 解法一:队伍最前面的那些女生不需要交换,后面的女生有两种状态:畅通无阻,前一个女生 ...
- Educational Codeforces Round 8 B 找规律
B. New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- codeforces D. Queue 找规律+递推
题目链接: http://codeforces.com/problemset/problem/353/D?mobile=true H. Queue time limit per test 1 seco ...
- Codeforces Gym 100114 A. Hanoi tower 找规律
A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descript ...
- Tetrahedron(Codeforces Round #113 (Div. 2) + 打表找规律 + dp计数)
题目链接: https://codeforces.com/contest/166/problem/E 题目: 题意: 给你一个三菱锥,初始时你在D点,然后你每次可以往相邻的顶点移动,问你第n步回到D点 ...
- 找规律/贪心 Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones
题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include &l ...
- 找规律 Codeforces Round #309 (Div. 2) A. Kyoya and Photobooks
题目传送门 /* 找规律,水 */ #include <cstdio> #include <iostream> #include <algorithm> #incl ...
随机推荐
- java 根据值获取枚举对象
关键方法: /** * 值映射为枚举 * * @param enumClass 枚举类 * @param value 枚举值 * @param method 取值方法 * @param <E&g ...
- Result Maps collection already contains value for com.xxx.x.dao.xxxMapper.Bas
springboot启动时候,报错如下: Result Maps collection already contains value for com.xxx.xx.dao.xxxxxMapper.Ba ...
- 【pwnable.kr】cmd1
最近的pwnable都是linux操作系统层面的. ssh cmd1@pwnable.kr -p2222 (pw:guest) 首先还是下载源代码: #include <stdio.h> ...
- excel提取数字
部分提取,那么就用=-LOOKUP(,-MID(A1,MIN(FIND({0;1;2;3;4;5;6;7;8;9},A1&1234567890)),ROW($1:$1024))) ------ ...
- 【转】在C#中?,?:和??
符号:?名称:可空类型修饰符.引用类型可以使用空引用表示一个不存在的值,而值类型通常不能表示为空.例如:string str=null; 是正确的,int i=null; 编译器就会报错.为了使值类型 ...
- 吴裕雄--天生自然C++语言学习笔记:C++ 数据结构
C/C++ 数组允许定义可存储相同类型数据项的变量,但是结构是 C++ 中另一种用户自定义的可用的数据类型,它允许存储不同类型的数据项. 结构用于表示一条记录,假设想要跟踪图书馆中书本的动态,可能需要 ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-facetime-video
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- hdu 4300 Clairewd’s message 字符串哈希
Clairewd’s message Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- MySQLWorkbench注释
不改变快捷键配置文件基础上 1. 通过菜单操作 Edit -> Format -> Un/comment 2. 键盘 (Windows 10, 其他操作系统未试过) Ctrl + / ( ...
- iOS 技术篇:从使用到了解block底层原理 (二)
block实质 序言 上篇文章中主要通过简单的demo展示了block的使用场景,本篇将基于上篇文章iOS 技术篇:从使用到了解block底层原理 (一)进一步了解block底层的实现原理. bloc ...