当前位置:网站首页>[exercise-7] (UVA 10976) fractions again?! (fraction split)
[exercise-7] (UVA 10976) fractions again?! (fraction split)
2022-07-06 15:56:00 【Flame car】
translate :
Enter a positive integer k, Find all positive integers x≥y, bring
1 k = 1 x + 1 y \frac{1}{k}=\frac{1}{x}+\frac{1}{y} k1=x1+y1
This question is also very interesting , Do some advanced calculation :
Since it is required to find all x,y, The enumerated object is naturally x,y 了 . But the problem is , How about the scope of enumeration ? from 1/12=1/156+1/13 It can be seen that ,x Comparable y Much larger . Should we enumerate endlessly ? Of course not. . because x≥y, Yes 1/x ≤1/y, therefore 1/k - 1/y ≤ 1/y, namely y≤2k. This only needs to be done in [k+1,2k] Enumeration in scope y, And then according to y Try to work out x that will do .
( Content from Purple Book )
That's great !
AC Code :
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+5;
const ll mod = 1e9+7;
int main()
{
int n;
while(cin>>n && n)
{
int cnt = 0;
for(int i=n+1;i<=2*n;i++)
if((i*n)%(i-n)==0)
cnt++;
cout<<cnt<<endl;
for(int i=n+1;i<=2*n;i++)
if((i*n)%(i-n)==0)
printf("1/%d = 1/%d + 1/%d\n",n,(i*n)/(i-n),i);
}
}
Write directly twice and calculate cnt One side of the output is because I'm too lazy ... There may be simple ways ?? Well, it should be about the same .
The middle judgment idea is like this :1/k = 1/x +1/y, in other words 1/k - 1/y = 1/x Is to meet the conditions .
The left side of the equation is simplified to y/ky - k/ky ==》 (y-k)/yk That is to say, as long as this formula can be reduced to 1/? Is to meet the conditions .
That is to say 1/(yk/(y-k)) The denominator of is an integer . That is to say yk%(y-k) ==0
So we get the formula in the code .
summary :
The problem of this formula , We should use unknown numbers to deduce several new formulas to simplify the problem .
Mainly push formula , If you can't push it out, you'll be finished ...
边栏推荐
- Learning record: Tim - Basic timer
- China's earthwork equipment market trend report, technical dynamic innovation and market forecast
- Opencv learning log 16 paperclip count
- Accounting regulations and professional ethics [4]
- Opencv learning log 19 skin grinding
- 信息安全-威胁检测-NAT日志接入威胁检测平台详细设计
- [exercise-7] crossover answers
- Information security - security professional name | CVE | rce | POC | Vul | 0day
- Learning record: how to perform PWM output
- Ball Dropping
猜你喜欢

VS2019初步使用

D - Function(HDU - 6546)女生赛

B - 代码派对(女生赛)

Penetration test (7) -- vulnerability scanning tool Nessus

Learning record: USART serial communication

C语言是低级和高级的分水岭

X-forwarded-for details, how to get the client IP

Optimization method of path problem before dynamic planning

Learning record: use stm32f1 watchdog
![mysql导入数据库报错 [Err] 1273 – Unknown collation: ‘utf8mb4_0900_ai_ci’](/img/e6/f4a696179282fe1f4193410c5a493a.png)
mysql导入数据库报错 [Err] 1273 – Unknown collation: ‘utf8mb4_0900_ai_ci’
随机推荐
【高老师UML软件建模基础】20级云班课习题答案合集
Learning records: serial communication and solutions to errors encountered
Cost accounting [19]
程序员的你,有哪些炫技的代码写法?
Learning record: understand systick system timer and write delay function
Matlab example: two expressions of step function
Ball Dropping
Cost accounting [17]
SSM框架常用配置文件
China's earthwork equipment market trend report, technical dynamic innovation and market forecast
基于web的照片数码冲印网站
Flink 使用之 CEP
渗透测试 ( 8 ) --- Burp Suite Pro 官方文档
差分(一维,二维,三维) 蓝桥杯三体攻击
CEP used by Flink
Determine the Photo Position
nodejs爬虫
力扣刷题记录
Printing quality inspection and verification system Industry Research Report - market status analysis and development prospect forecast
Interesting drink