题目:

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.

Input

A single line containing one integer nn (3≤n≤10^9) — the integer Little C has.

Output

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.

Examples
input
3
output
1 1 1
input
233
output
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) 【数学】的更多相关文章

  1. Codeforces Round #511 (Div. 2)

    Codeforces Round #511 (Div. 2) #include <bits/stdc++.h> using namespace std; int n; int main() ...

  2. 2018.9.21 Codeforces Round #511(Div.2)

    只写了AB,甚至还WA了一次A题,暴露了蒟蒻的本质=.= 感觉考的时候有好多正确或和正解有关的思路,但是就想不出具体的解法或者想的不够深(长)(怕不是过于鶸) 话说CF的E题怎么都这么清奇=.= A. ...

  3. Codeforces Round #511 (Div. 2):C. Enlarge GCD(数学)

    C. Enlarge GCD 题目链接:https://codeforces.com/contest/1047/problem/C 题意: 给出n个数,然后你可以移除一些数.现在要求你移除最少的数,让 ...

  4. Codeforces Round #511 (Div. 2)-C - Enlarge GCD (素数筛)

    传送门:http://codeforces.com/contest/1047/problem/C 题意: 给定n个数,问最少要去掉几个数,使得剩下的数gcd 大于原来n个数的gcd值. 思路: 自己一 ...

  5. Codeforces Round #511 (Div. 1) C. Region Separation(dp + 数论)

    题意 一棵 \(n\) 个点的树,每个点有权值 \(a_i\) .你想砍树. 你可以砍任意次,每次你选择一些边断开,需要满足砍完后每个连通块的权值和是相等的.求有多少种砍树方案. \(n \le 10 ...

  6. Codeforces Round #511 Div.1 A Div.2 C

    嗯切一题走人很开心. gzy-50分比我还惨. 题意:有n个数,去掉尽量少的数使得剩下数的gcd变大. 首先把这n个数都除以gcd,就变成了去掉尽量少的数使得gcd不等于1. 可以枚举一个质数,然后统 ...

  7. 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 ...

  8. 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 ...

  9. Codeforces Round #511 (Div. 2) C. Enlarge GCD

    题目链接 题目就是找每个数的最小素因子,然后递归除,本来没啥问题,结果今天又学习了个新坑点. 我交了题后,疯狂CE,我以为爆内存,结果是,我对全局数组赋值, 如果直接赋值,会直接在exe内产生内存,否 ...

随机推荐

  1. 固本培元之三:Convert、运算符、流程控制语句、ref/out/in三种参数类型

    一.Convert类常用的类型转换方法Convert.ToInt32() 转换为整型(int)Convert.ToChar() 转换为字符型(char)Convert.ToString() 转换为字符 ...

  2. 720. Longest Word in Dictionary 能连续拼接出来的最长单词

    [抄题]: Given a list of strings words representing an English Dictionary, find the longest word in wor ...

  3. Free GIS Software

    Refer to There are lots of free gis software listed in the website: http://www.freegis.org/ http://w ...

  4. R语言读取MySQL数据表

    1.R中安装RODBC包 install.packages("RODBC") 2.在Windows系统下安装MySQL的ODBC驱动 注意区分32位和64位版本: http://d ...

  5. MagicNotes:如何迈向工作的坦途

    MagicNotes,思绪随风飞扬,不抓住写下来明天就会忘记了. 昨晚在知乎上偶尔看到 @雨农 的关于“为什么我那么努力,吃了那么多苦,也没见那么优秀?”的一个回复,心里有所触动. 本人专科毕业3-4 ...

  6. 运行maven build报错No goals have been specified for this build.

    运行maven报错: [ERROR] No goals have been specified for this build. You must specify a valid lifecycle p ...

  7. datagrid 自定义 pager

    $(document).ready(function(){ var p = $('.easyui-datagrid').datagrid('getPager'); $(p).pagination({ ...

  8. GCC 显示所有的warning option

    此事需求的来源是有要求调查,gcc中的那些warning是有问题的,代码必须要修改,那些事需要确认的,就要显示所有的warning选项是什么 查了下,方法如下 显示所有的warning和warning ...

  9. C# 属性与字段

    属性和字段的区别: 属性是逻辑字段,是字段的扩展,并不占用实际的内存:而字段占用内存空间. 属性可以被其他类访问:而非public的字段不能被直接访问. 属性可以对接受的数据在范围上做限定:而字段不能 ...

  10. Struts2学习第3天--OGNL、EL、值栈

    JAVA中的OGNL: 1 调用对象的方法: 2 访问对象的静态方法: 3 获取OGNLContext.Root中的数据. User: 4 访问Context: 关键还是在Struts2环境中的使用: ...