F - 等式(1/x + 1/y = 1/n)
链接:https://www.nowcoder.com/acm/contest/90/F
来源:牛客网
题目描述
给定n,求1/x + 1/y = 1/n (x<=y)的解数。(x、y、n均为正整数)
输入描述:
在第一行输入一个正整数T。接下来有T行,每行输入一个正整数n,请求出符合该方程要求的解数。(1<=n<=1e9)
输出描述:
输出符合该方程要求的解数。
输入
3 1 20180101 1000000000
输出
1 5 181
思路:
1/x + 1/y = 1/n
-> yn + xn - xy = 0
-> yn + xn - xy -n^2 +n^2 = 0
-> n^2 = (n - x) * ( n - y)
即:求n^2的约数组合数,n^2的质因数与n的质因数相同,个数为n的两倍
代码:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define is_lower(c) (c >= 'a' && c <= 'z')
#define is_upper(c) (c >= 'A' && c <= 'Z')
#define is_alpha(c) (is_lower(c) || is_upper(c))
#define is_digit(c) (c >= '0' && c <= '9')
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define PI acos(-1)
#define IO \
ios::sync_with_stdio(); \
cin.tie(); \
cout.tie();
#define For(i, a, b) for (int i = a; i <= b; i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
const ll inf = 0x3f3f3f3f;
;
const ll inf_ll = (ll)1e18;
const ll maxn = 100005LL;
const ll mod = 2012LL;
+ ;
int main() {
int T,n;
cin>>T;
while(T--) {
cin>>n;
]={};
;
; i * i <= n; i++) {
) {
) {
ans[len]++;
n /= i;
}
len++;
}
}
)
ans[len]++;
ll res = ;
; i <= len ; i++)
res *= ans[i] * + ;
res = (res + ) / ;
cout << res << endl;
}
}
F - 等式(1/x + 1/y = 1/n)的更多相关文章
- Problem F: 等式
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 104 Solved: 22[Submit][Status][Web Board] Descriptio ...
- 设x,y是概率空间(Ω,F,P)上的拟可积随机变量,证明:X=Y a.e 当且仅当 xdp = ydp 对每个A∈F成立。Q: X=Y almost surely iff ∀A∈G∫AXdP=∫AYdP
E{XE{Y|C}}=E{YE{X|C}} 现在有没有适合大学生用的搜题软件呢? https://www.zhihu.com/question/51935291/answer/514312093 ...
- C语言程序设计100例之(18):火柴棒等式
例18 火柴棒等式 用n根火柴棍,可以拼出多少个形如“A+B=C”的等式?等式中的A.B.C是用火柴棒拼出的整数(若该数非零,则最高位不能是0).用火柴棒拼数字0~9的拼法如图1所示. 图1 用 ...
- Y Combinator
常见的例子 阶乘函数: fact = (a) -> if a > 0 then a * fact(a - 1) else 1 问题的提出 如上,在fact函数中调用了fact本身,无法使用 ...
- codeforces Gym 100187F F - Doomsday 区间覆盖贪心
F. Doomsday Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/F ...
- Codeforces Bubble Cup 8 - Finals [Online Mirror] F. Bulbo DP
F. Bulbo Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/575/problem/F Des ...
- 矩阵的f范数及其求偏导法则
转载自: http://blog.csdn.net/txwh0820/article/details/46392293 矩阵的迹求导法则 1. 复杂矩阵问题求导方法:可以从小到大,从scalar到 ...
- AtCoder Regular Contest 066 F Contest with Drinks Hard
题意: 你现在有n个题目可以做,第i个题目需要的时间为t[i],你要选择其中的若干题目去做.不妨令choose[i]表示第i个题目做不做.定义cost=∑(i<=n)∑(i<=j<= ...
- 江西财经大学第一届程序设计竞赛 F题 解方程
链接:https://www.nowcoder.com/acm/contest/115/F来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536 ...
随机推荐
- 【bzoj5070】危险的迷宫 费用流
题目描述 JudgeOnline/upload/201710/55.doc 输入 第一行是两个整数A与B(1≤A,B≤10),中间用空格分隔,表示该迷宫是A行B列的. 第2行至第A+1行,每行有B个1 ...
- BZOJ4487 JSOI2015染色问题(组合数学+容斥原理)
逐个去除限制.第四个限制显然可以容斥,即染恰好c种颜色的方案数=染至多c种颜色的方案数-染至多c-1种颜色的方案数+染至多c-2种颜色的方案数…… 然后是限制二.同样可以容斥,即恰好选n行的方案数=至 ...
- [Leetcode] Path Sum路径和
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all ...
- BZOJ1876 [SDOI2009]SuperGCD 【高精 + GCD优化】
题目 Sheng bill有着惊人的心算能力,甚至能用大脑计算出两个巨大的数的GCD(最大公约 数)!因此他经常和别人比 赛计算GCD.有一天Sheng bill很嚣张地找到了你,并要求和你比 赛,但 ...
- BZOJ day2
十六题...(好难啊) 1051105910881191119214321876195119682242243824562463276128184720
- git使用笔记(九)操作原理
By francis_hao Nov 27,2016 参考[1]的一张图已经把git的基本原理描述的很清楚了,如下: 下面以实例演示其过程,需要用到两个命令cat-file和ls-fil ...
- c++编辑器下载地址
https://msdn.itellyou.cn/ 输入上述地址选中下图所示的按钮:
- ZooKeeper Watcher注意事项
zookeeper watch的定义如下:watch事件是一次性触发器,当watch监视的数据发生变化时,通知设置了该watch的client,即watcher. 需要注意三点: 1.一次性触发器 c ...
- Install the AWS Command Line Interface on Linux
Install the AWS Command Line Interface on Linux You can install the AWS Command Line Interface and i ...
- tomcat编码配置
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" ...