【数论】HDU 4143 A Simple Problem】的更多相关文章

题目内容 给出一个正整数\(n\),找到最小的正整数\(x\),使之能找到一个整数\(y\),满足\(y^2=n+x^2\). 输入格式 第一行是数据组数\(T\),每组数据有一个整数\(n\). 输出格式 输出\(T\)行,表示\(x\),若找不到答案输出\(-1\). 数据范围 \(0\le n\le 10^9\) 样例 2 2 3 样例输出 -1 1 思路 A Not Simple Problem 原式变形一下: \(n=(y+x)(y-x)\) 因此找到\(n\)的两个因子,设为\(a_…
题目链接 题意 : 就是给你一个数n,让你输出能够满足y^2 = n +x^2这个等式的最小的x值. 思路 : 这个题大一的时候做过,但是不会,后来学长给讲了,然后昨天比赛的时候二师兄看了之后就敲了,我也想了一会儿才想起来,真是惭愧啊..... 其实就是将上边那个式子变一下:(y-x)*(y+x) = n ,然后接下来就去枚举(y-x)的值,因为手算了几组数据,发现当这个值越靠近√n时,x的值越小,其实看这个等式也可以看出来,所以枚举的时候从√n这里开始往下枚举就行,然后再看(y-x)+(y+x…
题目 题意:给n,求x; 直接枚举肯定超时, 把给的式子变形, (y+x)(y-x) = n; 令y-x = b, y+x = a; 枚举b, b 的范围肯定是sqrt(n),  y = (a+b)/2;  x = (a-b)/2; b越大, x越小, 所以倒着枚举b #include <iostream> #include <cstdio> #include <cmath> #include <cstring> using namespace std; i…
求一个最小的正整数x,使得(y + x) (y - x) = n成立 考虑一下n的分解因式. 可能会想到枚举n的约数,那么a * b = n成立,取最小的x即可 但是要枚举到n / 2,这样会超时. 因为要使得a * b = n,那么a和b中最大的数字最多是sqrt(n),因为不可能是两个大于sqrt(n)的数字相乘得到n的(大过n了) 所以我可以枚举 1 -- sqrt(n)中n的约数,得到a和b,然后反转一下a和b,就是所有a * b = n的结果 例如18的约数 1.2.3.6.9.18…
题目 For a given positive integer n, please find the saallest positive integer x that we can find an integer y such that \(y^2 = n +x^2\). 输入 The first line is an integer \(T\), which is the the nuaber of cases. Then T line followed each containing an…
A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5339    Accepted Submission(s): 1693 Problem Description Let A1, A2, ... , AN be N elements. You need to deal with…
A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5402    Accepted Submission(s): 1710 Problem Description Let A1, A2, ... , AN be N elements. You need to deal with…
传送门 •题意 一直整数$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}=…
Problem Description When Teddy was a child , he was always thinking about some simple math problems ,such as "What it's 1 cup of water plus 1 pile of dough .." , "100 yuan buy 100 pig" .etc.. One day Teddy met a old man in his dream ,…
题目链接 Problem Description Zty很痴迷数学问题..一天,yifenfei出了个数学题想难倒他,让他回答1 / n.但Zty却回答不了^_^. 请大家编程帮助他. Input 第一行整数T,表示测试组数.后面T行,每行一个整数 n (1<=|n|<=10^5). Output 输出1/n. (是循环小数的,只输出第一个循环节). Sample Input 4 2 3 7 168 Sample Output 0.5 0.3 0.142857 0.005952380 分析:…
http://acm.hdu.edu.cn/showproblem.php?pid=4267 [思路] 树状数组的区间修改:在区间[a, b]内更新+x就在a的位置+x. 然后在b+1的位置-x 树状数组的单点查询:求某点a的值就是求数组中1~a的和. (i-a)%k==0把区间分隔开了,不能直接套用树状数组的区间修改单点查询 这道题的K很小,所以可以枚举k,对于每个k,建立k个树状数组,所以一共建立55棵树 所以就可以多建几棵树..然后就可以转换为成段更新了~~ [AC] #include<b…
题意:给一个序列,操作1:给区间[a,b]中(i-a)%k==0的位置 i 的值都加上val  操作2:查询 i 位置的值 解法:树状数组记录更新值. 由 (i-a)%k == 0 得知 i%k == a%k,又因为k <= 10,想到建55棵树状数组,即对每个(k,x%k)都建一棵树状数组,每次更新时,在第(k,a%k)棵树状数组上更新a这个点,更新值为val,然后再b+1处更新值为-val,即在[a,b]内更新了val. 查询pos的时候,求出每一个树状数组(k,pos%k)的sum值即可.…
以前似乎做过类似的不过当时完全不会.现在看到就有点思路了,开始还有洋洋得意得觉得自己有不小的进步了,结果思路错了...改了很久后测试数据过了还果断爆空间... 给你一串数字A,然后是两种操作: "1 l r k c":意思是当 l=<i<=r 对(i-a)%k = =0 的每个 Ai 都增加 c (1=<k<=10) "2 i" :意思是求出 Ai 一看就是区间更新和单点查询,其实可以用树状数组做,可是觉得线段树好弄一点,结果成功入坑...…
链接:Here! 思路:模拟除法,当余数再次出现的时候一定是遇到了循环节( 可看下图例子 ),否则的话继续除法的步骤,直到被除数为 0 . 注意:这道题不需要重新申请一个数组来单独存放答案,如果符合要求直接输出即可,如果申请一个数组来存放答案,每次都需要情况答案数组,极大的浪费了时间,很容易T /************************************************************************* > File Name: hdu2522.cpp >…
A simple problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3702 Accepted Submission(s): 1383 Problem Description Zty很痴迷数学问题..一天,yifenfei出了个数学题想难倒他,让他回答1 / n.但Zty却回答不了^_^. 请大家编程帮助他. Input 第一行…
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5349 MZL's simple problem Description A simple problemProblem DescriptionYou have a multiple set,and now there are three kinds of operations:1 x : add number x to set2 : delete the minimum number (if the…
A Very Simple Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1022    Accepted Submission(s): 500 Problem Description This is a very simple problem. Given three integers N, x, and M, you…
HDU 4974 A simple water problem pid=4974" target="_blank" style="">题目链接 签到题,非常easy贪心得到答案是(sum + 1) / 2和ai最大值的最大值 代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N =…
pid=4972" target="_blank" style="">题目链接:hdu 4972 A simple dynamic programming problem 题目大意:两支球队进行篮球比赛,每进一次球后更新比分牌,比分牌的计数方法是记录两队比分差的绝对值,每次进球的分可能是1,2,3分. 给定比赛中的计分情况.问说最后比分有多少种情况. 解题思路:分类讨论: 相邻计分为1-2或者2-1的时候,会相应有两种的的分情况 相邻计分之差大于3或…
A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4032    Accepted Submission(s): 1255 Problem Description Let A1, A2, ... , AN be N elements. You need to deal with…
A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4000    Accepted Submission(s): 1243 Problem Description Let A1, A2, ... , AN be N elements. You need to deal with…
MZL's simple problem Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 740    Accepted Submission(s): 357 Problem Description A simple problemProblem DescriptionYou have a multiple set,and now the…
A Simple Problem with Integers Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other i…
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-size: 10.5000pt } h1 { margin-top: 5.0000pt; margin-bottom: 5.0000pt; text-align: center; font-family: 宋体; color: rgb(26,92,200); font-weight: bold; fo…
A simple problem Accepted : 30   Submit : 303 Time Limit : 15000 MS   Memory Limit : 655360 KB Problem Description There is a simple problem. Given a number N. you are going to calculate N%1+N%2+N%3+...+N%N. Input First line contains an integer T, th…
http://acm.hdu.edu.cn/showproblem.php?pid=2522 学习://除数的运算的应用和算法.除法的本质,如果余数出现重复就表示有循环节 A simple problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2795    Accepted Submission(s): 984 Proble…
A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 347161    Accepted Submission(s): 67385 Problem Description I have a very simple problem for you. Given two integers A and B, you…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3483 A Very Simple Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 945    Accepted Submission(s): 471 Problem Description This is a very si…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 Problem DescriptionI have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B. InputThe first line of the input contains an integer T(1<=T<=20) whic…
数字的反转: 就是将数字倒着存下来而已.(*^__^*) 嘻嘻…… 大致思路:将数字一位一位取出来,存在一个数组里面,然后再将其变成数字,输出. 详见代码. while (a) //将每位数字取出来,取完为止 { num1[i]=a%; //将每一个各位取出存在数组里面,实现了将数字反转 i++; //数组的变化 a/=; } 趁热打铁 例题:hdu 4554 叛逆的小明 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4554 叛逆的小明 Time…