[hdu4627 The Unsolvable Problem]数论】的更多相关文章

题意:给一个数n,找一个正整数x<n,使得x和n-x的最小公倍数最大. 思路:显然x和n-x越接近越好,gcd必须为1(贪心).从大到小考虑x,如果n为奇数,则答案就是x=n/2,如果n为偶数,令n=2k,如果k为奇数,且大于1则x=k-2否则x=k,如果k为偶数则x=k-1.以上结论基于以下两个事实: (1)相邻两个数的gcd为1 (2)相邻两个奇数的gcd为1 (3)1和1的gcd为1 写的时候没用到这些事实,直接从n/2向下枚举,当gcd为1时得到答案 1 2 3 4 5 6 7 8 9…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4627 对n除个2,然后考虑下奇偶... //STATUS:C++_AC_15MS_228KB #include <functional> #include <algorithm> #include <iostream> //#include <ext/rope> #include <fstream> #include <sstream>…
The Unsolvable Problem 题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=45783 题意: 给定一个整数n(2 < = x < = 10^9),我们应该找到一双正整数a,b,满足a + b = n和a,b的最小公倍数是尽可能大: 输出这个最大的最小公倍数. 题目要求要T组案例. 案例: Sampl Input 3 2 3 4 Sample Output 1 2 3 解题思路: 由于2&…
Problem Description There are many unsolvable problem in the world.It could be about one or about zero.But this time it is about bigger number. Given an integer n(2 <= n <= 109).We should find a pair of positive integer a, b so that a + b = n and [a…
2013-07-30 20:35 388人阅读 评论(0) 收藏 举报 http://acm.hdu.edu.cn/showproblem.php?pid=4627 The Unsolvable Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 230    Accepted Submission(s): 136 Prob…
链接: http://acm.hdu.edu.cn/showproblem.php?pid=4627 The Unsolvable Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 243    Accepted Submission(s): 143 Problem Description There are many u…
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82974#problem/E 解题思路:数论,从一个数的中间开始往两边找,找到两个互质的数就是,若这个数为奇数,则就是(n/2)*(n-n/2),若这个数是偶数,则还需要判断这个数的一半是否是偶数,若是偶数,则就是(n/2+1)*(n/2-1),若是奇数,则就是(n/2+2)*(n/2-2) 程序代码: #include <iostream> #define l long l…
11490 - Just Another Problem option=com_onlinejudge&Itemid=8&page=show_problem&category=474&problem=2485&mosmsg=Submission+received+with+ID+13809788" target="_blank" style="">题目链接 题意:有S个士兵.排成一个矩阵,矩阵中能够有两个洞,要…
Problem Description Given two positive integers a and b,find suitable X and Y to meet the conditions:                                                        X+Y=a                                              Least Common Multiple (X, Y) =b   InputInp…
B. A Trivial Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer m and asks f…
A Trivial Problem Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer m and asks for the number of positive integers n, such that the factorial of n ends with exactly m zeroes. Are you among thos…
原题链接:http://codeforces.com/contest/798/problem/C 题意:有一个数列A,gcd(a1,a2,a3...,an)>1 时称这个数列是“漂亮”的.存在这样的操作,使ai,ai+1变为(ai-ai+1), (ai+ai+1).问最少进行这样的操作使数列是“漂亮”的. 思路:考虑gcd(a1,a2,a3...,an)>1 的情况: 我们对ai,ai+1进行两次操作可以得到2ai,2ai+1,也就是说一对相邻的数字最多操作2次使它们的gcd=2>1.而…
http://acm.hdu.edu.cn/showproblem.php?pid=4627 分类讨论一下就可以 代码: #include<iostream> #include<cstdio> #include<algorithm> #include<string> #include<cstring> #include<cmath> #include<set> using namespace std; typedef lo…
给你一个数 n ( 2 <= n <= 109 ),现在需要你找到一对数a, b (a + b = n),并且使得LCM(a, b)尽可能的大,然后输出最大的 LCM(a, b). (为什么我每次看到题目都想去暴力..Orz    题外话) 这道题先对  n = 2 的情况进行判断,从输出可以知道 n =  2 的时候 ans =  1.接着对 n 进行分情况讨论.当 n = 2k + 1 的时候,ans = k * (k + 1). 当 n = 2k 的时候: 当 k 为偶数的时候 ans…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4627 题目大意:给定一个整数n(2 <= n <= 109),满足a+b=n并且[a,b]的最小公倍数最大. 分析:相当简单的的一道题,因为生病好久没做题目,杭电居然是要用__int64,用long long反而错误,为此,WA了无数遍 代码如下: # include<iostream> # include<cstdio> # include<cmath> us…
题意描述:给出一个n,要求在所有满足n = a+b的a和b里面求a和b的最小公倍数最大的两个数的最小公倍数. 解题报告:比赛的时候看到这个题的第一反应就是寻找这两个数一定是在a和b比较接近的地方找,这样才能保证a和b的最小公倍数最大,首先,奇数和偶数是一定要分开的讨论的,因为奇数和偶数的一半是不同的,奇数的一半可能就是所要的结果,但是偶数的一半可以确定一定不是所要的结果,因为偶数一半刚好a和b就相等了,最小公倍数就是他们本身了,这是最小的了,然后偶数里面又要分开讨论,一种是这个偶数的一半是奇数,…
题意:给定 n,k,求 while(i <=n) k % i的和. 析:很明显是一个数论题,写几个样例你会发现规律,假设 p = k / i.那么k  mod i = k - p*i,如果 k / (i+1) 也是p,那么就能得到 : k mod (i+1) = k - p*(i+1) = k mod i - p.所以我们就能得到一个等差数列 k mod (i+1) - k mod i = -p,首项是 p % i. 代码如下: #pragma comment(linker, "/STAC…
做法 与\(x\)互质的数填不同的数,把有向关系表示出来,发现边数是不能承受的 反过来想,成倍数关系填相同的数,把这些数想象成一条链,而这条链开始的数一定是质数,\(\sum\limits_{prime_i}\frac{n}{prime_i}\)是可以承受的 把这条链的点赋一个相同的值 Code #include<bits/stdc++.h> using namespace std; typedef int LL; const LL maxn=1e6+9; inline LL Read(){…
传送门 •题意 一直整数$a,b$,有 $\left\{\begin{matrix}x+y=a\\ LCM(x*y)=b \end{matrix}\right.$ 求$x,y$ •思路 解题重点:若$gcd(p,q)=1$,则$gcd(p+q,pq)=1$ 设$gcd(x,y)=g$,令$p=\frac{x}{g},q=\frac{y}{g}$,$p,q$互素 则$\left\{\begin{matrix}x+y=p*g+q*g=(p+q)g=a\\ LCM(x,y)=\frac{xy}{g}=…
E. Ehab's REAL Number Theory Problem 数论+图论 求最小环 题目大意: 给你一个n大小的数列,数列里的每一个元素满足以下要求: 数据范围是:\(1<=a_i<=10^6\) \(a_i\) 最多只有7个因数 题目要求在这个数列找到一个最短的子数列,子数列的所有的数相乘是一个完全平方数. 题解: 这个题对于 \(x^{3}\) 应该等价于 \(x\) ,其实就是可以除去 \(a_i\)中的所有的平方项,显而易见,这个并不影响答案. 因为 \(a_i\) 最多只…
HDU 4622 Reincarnation 枚举字符串的起点,构造后缀自动机,每次插入一个字符,就能统计得到当前不同字串的个数,预处理出所有的询问. #include<cstdio> #include<cstring> #define MAXN 2010 #define MAXM 26 int res[MAXN][MAXN]; char str[MAXN]; struct node { node *next[MAXM]; node *pre; int step; int tot;…
Description There are many unsolvable problem in the world.It could be about one or about zero.But this time it is about bigger number. Given an integer n(2 <= n <= 10 9).We should find a pair of positive integer a, b so that a + b = n and [a, b] is…
今天悲剧了,各种被虐啊,还是太年轻了 Crime 这道题目给的时间好长,第一次就想到了暴力,结果华丽丽的TLE了. 后来找了一下,发现前24个是1, 2, 6, 12, 72, 72, 864, 1728, 13824, 22032, 555264, 476928, 17625600, 29599488, 321115392, 805146624, 46097049600, 36481536000, 2754120268800, 3661604352000, 83905105305600, 19…
HDU 4627 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Description There are many unsolvable problem in the world.It could be about one or about zero.But this time it is about bigger number. Given an integer n(2 <=…
Description There are many unsolvable problem in the world.It could be about one or about zero.But this time it is about bigger number. Given an integer n(2 <= n <= 10 9).We should find a pair of positive integer a, b so that a + b = n and [a, b] is…
原文 Be healthier and happier by spending time in the sun In the dead of winter,we don't typically think about spending time outside,but according to many medical experts,we should. The sun is our greatest source of a vitamin that is essential for good…
网址: https://www.spinellis.gr/cscout/ https://www2.dmst.aueb.gr/dds/cscout/index.html https://github.com/dspinellis/cscout 还有一个工具叫Xrefactory,它可以分析c++程序. cscout只能分析c程序.具体如下: A tool adopting an approach similar to ours is Vittek's Xrefactory [59]. Its f…
题目链接 A - Wrestling Match (二分图染色) 题意略坑(没有说好的玩家一定能打过差的玩家啊啊~~) 典型的二分图染色问题,每个玩家看成一个点,把相互较量过的玩家之间连边,好的玩家染成黑色,差的玩家染成白色.先把能确定颜色的点都确定下来,然后剩下的点判断是不是二分图,推导过程中发现矛盾立即返回No.如果一个点没有和其他任何点相连且颜色不确定也返回No. #include<bits/stdc++.h> using namespace std; typedef long long…
[题解]CF986E Prince's Problem(树上差分+数论性质) 题目大意: 给定你一棵树,有点权\(val_i\le 10^7\).现在有\(m\)组询问给定参数\(x,y,w\)问你对于\((x->y)\)的路径经过的点集\(P\),问你这个东西: \[ \prod_{u \in P} {\mathrm{gcd}(w,val_u)} \mod 1000000007 \] 考虑这样一种做法: 把询问差分成 \[ ans(1,x) \times ans(1,y) \times \ma…
X problem      X问题     Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)    Total Submission(s): 4358 Accepted Submission(s): 1399 Problem Description     求在小于等于N的正整数中有多少个X满足:X mod a[0] = b[0], X mod a[1] = b[1], X mod…