Divisor Subtraction
Description
You are given an integer number nn. The following algorithm is applied to it:
- if n=0, then end algorithm;
- find the smallest prime divisor d of n;
- subtract dd from n and go to step 1.
Determine the number of subtrations the algorithm will make.
Input
The only line contains a single integer nn (2≤n≤10^10).
Output
Print a single integer — the number of subtractions the algorithm will make.
Sample Input
5
1
4
2
Hint
In the first example 5 is the smallest prime divisor, thus it gets subtracted right away to make a 0.
In the second example 2 is the smallest prime divisor at both steps.
题解:给你一个数n,找它的最小素因子,每回减去,直到n=0,素因子均为奇数(除了2),奇-奇=偶,例如15,标准答案应该为7而不是5,在1e5内没有素因子时,答案为1。
代码如下:
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>
#define memset(x,y) memset(x,y,sizeof(x))
#define swap(a,b) (a=a+b,b=a-b,a=a-b)
#define debug(x) cout<<x<<" "<<endl
#define rson i << 1 | 1,m + 1,r
#define e 2.718281828459045
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define read(x) scanf("%d",&x)
#define put(x) printf("%d\n",x)
#define lowbit(x) (x&(-x))
#define lson i << 1,l,m
#define INF 0x3f3f3f3f
#define ll long long
#define mod 1001113
#define N 100000000
#define PI acos(-1)
#define eps 1.0e-6
#define maxn 27
//std::ios::sync_with_stdio(false);
//cin.tie(NULL);
//const int maxn=;
using namespace std; int main()
{
ll n;
cin>>n;
for(ll i=;i*i<=n;i++)
{
if(n%i==)
{
cout<<+(n-i)/<<endl;
return ;
}
}
cout<<""<<endl;
return ;
}
Divisor Subtraction的更多相关文章
- B. Divisor Subtraction
链接 [http://codeforces.com/contest/1076/problem/B] 题意 给你一个小于1e10的n,进行下面的运算,n==0 结束,否则n-最小质因子,问你进行多少步 ...
- CodeForces-1076B Divisor Subtraction 找规律
题目链接:https://vjudge.net/problem/CodeForces-1076B 题意: 题目要求给定一个数,要求每次减去其最小素因数(既是素数又是其因数),问直到n=0需要做几次运算 ...
- CF1076B Divisor Subtraction 题解
Content 给定一个数 \(n\),执行如下操作: 如果 \(n=0\) 结束操作. 找到 \(n\) 的最小质因子 \(d\). \(n\leftarrow n-d\) 并跳到操作 \(1\). ...
- Educational Codeforces Round 54 (Rated for Div. 2) Solution
A - Minimizing the String solved 题意:给出一个字符串,可以移掉最多一个字符,在所有可能性中选取一个字典序最小的. 思路:显然,一定可以移掉一个字符,如果移掉的字符的后 ...
- Educational Codeforces Round 54 (Rated for Div. 2) ABCD
A. Minimizing the String time limit per test 1 second memory limit per test 256 megabytes Descriptio ...
- codeforces1076 A.B.C.D.E
1076A 1076B 1076C 1076D 1076D A. Minimizing the String You are given a string s consisting of n low ...
- CoderForces Round54 (A~E)
ProblemA Minimizing the String 题目链接 题解:这一题读完题就写了吧.就是让你删除一个字母,使得剩下的字符组成的字符串的字典序最小:我们只要第一个当前位置的字符比下一个字 ...
- Codeforces Educational Codeforces Round 54 题解
题目链接:https://codeforc.es/contest/1076 A. Minimizing the String 题意:给出一个字符串,最多删掉一个字母,输出操作后字典序最小的字符串. 题 ...
- Codeforces Edu Round 54 A-E
A. Minimizing the String 很明显,贪心之比较从前往后第一个不一样的字符,所以可以从前往后考虑每一位,如果把它删除,他这一位就变成\(str[i + 1]\),所以只要\(str ...
随机推荐
- Win+E、D等快捷键失灵
[摘要]:系统win+e等快捷键失效不能使用. [问题分析]:软件或其他操作更改了注册表信息导致. [解决方案]: 1.在开始运行输入regedit点击确定 2.在打开的注册表编辑器找到HKEY_CU ...
- Pandas: 使用str.replace() 进行文本清洗
str.replace()可以一次处理一整个Series.str.replace()的正式形式为 Series.str.replace(pat, repl) ,其中pat为想要寻找的模式,一般为正则表 ...
- iOS 开发 Tips
1.MVVM 的优点 MVVM 兼容 MVC,可以先创建一个简单的 View Model,再慢慢迁移. MVVM 使得 app 更容易测试,因为 View Model 部分不涉及 UI. MVVM 最 ...
- [C++ Primer Plus] 第9章、内存模型和名称空间(一)程序清单
程序清单9.9(静态存储连续性.无链接性) #include<iostream> using namespace std; ; void strcount(const char *str) ...
- sql 中 and 和 or的坑
请参考以下链接 https://blog.csdn.net/u011064736/article/details/70257366
- python链接mysql获得某列最大值
import pymysqlconn = pymysql.connect(host='10.1.2.198', port= 3306 ,user='root',passwd='123456',db=' ...
- Python3学习笔记----生成器
生成器的作用 生成器可以在循环的过程中推算出后续的元素,不必创建完整的list,从而节省大量空间. 生成器的创建 1.把一个列表生成式的 [ ] 改写为( ) # -*- coding: UTF-8 ...
- 当 C++ 遇上音乐
前几天在洛谷日报征文中看到了这样一篇文章:C++不止能做题.作为原来校管弦乐队的一名成员,而后因为信息完全放弃了管弦乐队,我看完是又激动又怀念.于是我自行去研究了一下:C++ 如何让蜂鸣器叫出乐曲. ...
- C语言--第1次作业
1.本章学习总结 1.1思维导图 1.2本章学习体会及代码量学习体会 1.2.1学习体会 经过一周C语言的正式课堂学习,不同于暑期时扒视频囫囵吞枣式学习,林丽老师的讲解详细异常,尽管已经学习了一部分内 ...
- three.js初探,立体几何入手(一)
前言:首先先推荐一篇博客,关于webgl原理,讲的非常之通俗易懂了 图解WebGL&Three.js工作原理 webGL可以理解为openGL ES2.0 (webGL2.0 - openG ...