A. Little C Loves 3 I Codeforces Round #511 (Div. 2) 【数学】
Little C loves number «3» very much. He loves all things about it.
Now he has a positive integer nn. He wants to split nn into 3 positive integers a,b,ca,b,c, such that a+b+c=na+b+c=n and none of the 3 integers is a multiple of 3. Help him to find a solution.
A single line containing one integer nn (3≤n≤10^9) — the integer Little C has.
Print 3 positive integers a,b,c in a single line, such that a+b+c=n and none of them is a multiple of 3
It can be proved that there is at least one solution. If there are multiple solutions, print any of them.
3
1 1 1
233
77 77 79
题意分析:
这题是一个比较单纯的数学题目,给你一个数n,你需要把他分解成3个数,,并且这3个数都不是3的倍数。
这题我想的是根据数的素数分解原理,因为每个数都可以表示成素数相乘。所以对于N,
如果N的素因子中没有3,那么我们另外两个数只要相加等于3的倍数,那么就一定是满足的。
如果N的素因子中有3,那么此时,3应该还有个最大幂指数t,并且3的t次幂是N的一个因子。现在就是对3的t次幂的分解。假设 b = N/(3^t)
对3的t次幂分解成3个不被3整除的数还是比较简单的,因为是3的次幂,所以肯定可以分解成3个3的(t-1)次幂,那么 其中任意两个数减去1,另外一个数加上1就满足了,再把这3个数都乘以b即满足。 代码:
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int N;
while(~scanf("%d", &N))
{
int cnt = 1;
if(N%3 != 0) //N不是3的倍数
{
printf("%d %d %d\n", 1, 2, N-3);
continue;
}
while(N%3 == 0) //提取N中3的t次幂因子。
{
cnt*=3;
N/=3;
}
int a, b, c, d;
d = cnt/3;
if(d%3==0)
{
a = (d-1)*N;
b = (d+2)*N;
c = (d-1)*N;
}
else //d==1
{
a = b = c = d*N;
}
printf("%d %d %d\n", a, b, c); }
return 0;
}
A. Little C Loves 3 I Codeforces Round #511 (Div. 2) 【数学】的更多相关文章
- Codeforces Round #511 (Div. 2)
Codeforces Round #511 (Div. 2) #include <bits/stdc++.h> using namespace std; int n; int main() ...
- 2018.9.21 Codeforces Round #511(Div.2)
只写了AB,甚至还WA了一次A题,暴露了蒟蒻的本质=.= 感觉考的时候有好多正确或和正解有关的思路,但是就想不出具体的解法或者想的不够深(长)(怕不是过于鶸) 话说CF的E题怎么都这么清奇=.= A. ...
- Codeforces Round #511 (Div. 2):C. Enlarge GCD(数学)
C. Enlarge GCD 题目链接:https://codeforces.com/contest/1047/problem/C 题意: 给出n个数,然后你可以移除一些数.现在要求你移除最少的数,让 ...
- Codeforces Round #511 (Div. 2)-C - Enlarge GCD (素数筛)
传送门:http://codeforces.com/contest/1047/problem/C 题意: 给定n个数,问最少要去掉几个数,使得剩下的数gcd 大于原来n个数的gcd值. 思路: 自己一 ...
- Codeforces Round #511 (Div. 1) C. Region Separation(dp + 数论)
题意 一棵 \(n\) 个点的树,每个点有权值 \(a_i\) .你想砍树. 你可以砍任意次,每次你选择一些边断开,需要满足砍完后每个连通块的权值和是相等的.求有多少种砍树方案. \(n \le 10 ...
- Codeforces Round #511 Div.1 A Div.2 C
嗯切一题走人很开心. gzy-50分比我还惨. 题意:有n个数,去掉尽量少的数使得剩下数的gcd变大. 首先把这n个数都除以gcd,就变成了去掉尽量少的数使得gcd不等于1. 可以枚举一个质数,然后统 ...
- C. Enlarge GCD Codeforces Round #511 (Div. 2)【数学】
题目: Mr. F has nn positive integers, a1,a2,…,an. He thinks the greatest common divisor of these integ ...
- B. Cover Points Codeforces Round #511 (Div. 2)【数学】
题目: There are nn points on the plane, (x1,y1),(x2,y2),…,(xn,yn)(x1,y1),(x2,y2),…,(xn,yn). You need t ...
- Codeforces Round #511 (Div. 2) C. Enlarge GCD
题目链接 题目就是找每个数的最小素因子,然后递归除,本来没啥问题,结果今天又学习了个新坑点. 我交了题后,疯狂CE,我以为爆内存,结果是,我对全局数组赋值, 如果直接赋值,会直接在exe内产生内存,否 ...
随机推荐
- IFC文件解析
什么是IFC? EXPRESS语言与IFC体系 一.IFC 1.IFC简介 IFC是一个数据交换标准, 用于不同系统交换和共享数据.当需要多个软件协同完成任务时, 不同系统之间就会出现数据交换和共享的 ...
- PCL点云库中的坐标系(CoordinateSystem)
博客转载自:https://blog.csdn.net/qq_33624918/article/details/80488590 引言 世上本没有坐标系,用的人多了,便定义了坐标系统用来定位.地理坐标 ...
- Apache apachectl命令
一.简介 apachectl命令是Apache的Web服务器前端控制工具,用以启动.关闭和重新启动Web服务器进程. 二.语法 http://www.jinbuguo.com/apache/menu2 ...
- 用JQuery获取输入框中的光标位置
(function ($, undefined) { $.fn.getCursorPosition = function () { var el = $(this).get(0); var pos = ...
- Robot Framework - 常用断言讲解
RobotFramework带有丰富的系统关键,使用时无需导入,直接使用,为写自动化用例带来了极大的方便:不能停留在知道或者是会得程度,只有熟练使用各关键字,才能提升自动化用例的写作效率. 下面将逐个 ...
- linux 的各个文件夹都是干什么用
http://www.ruanyifeng.com/blog/2012/02/a_history_of_unix_directory_structure.html http://www.pathnam ...
- Java SimpleDateFormat工具类
package AnimalDemo; import java.text.ParseException; import java.text.SimpleDateFormat; import java. ...
- 使用dockerfile-maven-plugin发布docker到私有仓库
要想拥有私有docker仓库,需要安装registry镜像,最新版时2.0,具体可以看文档:https://docs.docker.com/registry/. 1. docker pull regi ...
- SSI简介 与 nginx开启SSI
Server Side Include : 服务器端嵌入 原理 : 将内容发送到浏览器之前,可以使用“服务器端包含 (SSI)”指令将文本.图形或应用程序信息包含到网页中.因为包含 SSI 指令的文件 ...
- h2数据库 安装部署
1.下载linux下的包,即全平台,网址:http://www.h2database.com/html/download.html 选择Platform-Independent Zip 2.把这个包上 ...