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 ...
随机推荐
- 在 Linux 安装 JDK 和 tomcat(菜鸡级别)
安装JDK 卸载 OPENJDK rpm -qa|grep jdk // 查看当前的jdk情况 yum -y remove java java-1.7.0-openjdk* // 卸载openjdk ...
- 【python】Python中给List添加元素的4种方法分享
List 是 Python 中常用的数据类型,它一个有序集合,即其中的元素始终保持着初始时的定义的顺序(除非你对它们进行排序或其他修改操作). 在Python中,向List添加元素,方法有如下4种方法 ...
- 对Web作用域变量进行迭代
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ pa ...
- final变量属性小记
final 修饰符对于类成员变量来说,具备语法上不可变的特性:对于类成员方法来说,具备语法上子类不可覆盖重写的特性(能被继承的前提下). 但 final 并不限制子类对父类被修饰声明的成员变量进行覆盖 ...
- Tile Cut~网络流入门题
Description When Frodo, Sam, Merry, and Pippin are at the Green Dragon Inn drinking ale, they like t ...
- Linux内存 性能调优
内存是影响Linux性能的主要因素之一,内存资源的充足与否直接影响应用系统的使用性能. free命令:监控Linux内存使用状况. 由上图可知,空闲内存是free+buffers+cached=155 ...
- elk,centos7,filebeat,elasticsearch-head集成搭建
1.安装 elasticsearch-5.2.2.tar.gz cd elasticsearch-5.2.2/bin ./elasticsearch -Ecluster.name=my_cluster ...
- WebOS系列-了解Wekbit【邓侃】
注:[转载请注明文章来源.保持原样] 出处:http://www.cnblogs.com/jyli/archive/2010/02/02/1660634.html 作者:李嘉昱 这是Kan老大的We ...
- css做中划线与文字排版
html: <div class="spilt"> <span class="left"></span> < ...
- 动态规划:划分DP
划分型动态规划之数的划分 先贴上2014年10月31日的那份代码,甚至怀念当时在机房YY这道题的场面 高中最快乐的时候.. #include<iostream> using namespa ...