HDU1792A New Change Problem(GCD规律推导)
A New Change Problem
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 533 Accepted Submission(s): 265
satisfy that GCD(A,B)=1.Here you can assume that there are enough coins
for both kinds.Please calculate the maximal value that you cannot pay
and the total number that you cannot pay.
should output the the maximal value that you cannot pay and the total
number that you cannot pay, and with one line of output for each line in
input.
/*************************************************************************
> File Name: HDU1792.cpp
> Author: LyuCheng
> Created Time: 2017年10月19日 星期四 02时56分57秒
************************************************************************/
/*
* 题意:给你两个素数,问你用这两个素数最大不能组成的数是什么,和有多少不能组成的数。
* 每个素数都可以用无数次
*
* 思路:A*x+B*y=t;
* 最大的不能组成:
* 那么t可以分成两部分,一部分是能让A整除的,另一部分是mod A的余数,当t>=A*B-B=B*(A-1)
* 时,1~(B*(A-1)) mod A 可以形成0~A-1的任何一个数,所以t>=A*B-B时一定能被组成,现在的问题
* 就是找小于A*B-B的第一个不能组成的,不能组成的条件就是小于A*B-B并且与他膜A同余的第一个数
* 也就是A*B-B-A
*
* 有多少不能组成的数:
* 从上边知道一个数不能组成的条件就是这个数是B的倍数,并且小于A*x+B*y且与他同余,那么有
* (A-1)*B: (A-1)*B-A , (A-1)*B-2*A ... (A-1)*B/A-1个,(之所以减一因为(A-1)*B是可以被组成的)
* (A-2)*B: (A-2)*B-A , (A-2)*B-2*A ...
* (A-3)*B: (A-3)*B-A , (A-3)*B-2*A ...
* ...
* B: B-A, ...
*
* 那么结果
* res= (A-1)*B/A-1+(A-1)*B/A-1+...+B/A-1
* = (A-1)*(B-1)/2;
* */
#include <bits/stdc++.h> using namespace std; int a,b; int main(){
while(scanf("%d%d",&a,&b)!=EOF){
printf("%d %d\n",a*b-a-b,(a-)*(b-)/);
}
return ;
}
HDU1792A New Change Problem(GCD规律推导)的更多相关文章
- 数学--数论--HDU1792A New Change Problem(GCD规律推导)
A New Change Problem Problem Description Now given two kinds of coins A and B,which satisfy that GCD ...
- UVA 1363 Joseph's Problem 找规律+推导 给定n,k;求k%[1,n]的和。
/** 题目:Joseph's Problem 链接:https://vjudge.net/problem/UVA-1363 题意:给定n,k;求k%[1,n]的和. 思路: 没想出来,看了lrj的想 ...
- HDU 2086 A1 = ? (找规律推导公式 + 水题)(Java版)
Equations 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2086 ——每天在线,欢迎留言谈论. 题目大意: 有如下方程:Ai = (Ai-1 ...
- 365. Water and Jug Problem (GCD or BFS) TBC
https://leetcode.com/problems/water-and-jug-problem/description/ -- 365 There are two methods to sol ...
- 数学--数论--HDU 1792 A New Change Problem (GCD+打表找规律)
Problem Description Now given two kinds of coins A and B,which satisfy that GCD(A,B)=1.Here you can ...
- Codeforces Gym 100015A Another Rock-Paper-Scissors Problem 找规律
Another Rock-Paper-Scissors Problem 题目连接: http://codeforces.com/gym/100015/attachments Description S ...
- FZU 2224 An exciting GCD problem(GCD种类预处理+树状数组维护)同hdu5869
题目链接:http://acm.fzu.edu.cn/problem.php?pid=2224 同hdu5869 //#pragma comment(linker, "/STACK:1024 ...
- hdu 1792 A New Change Problem(互质数之间最大不能组合数和不能组合数的个数)
题意:求互质的m和n的最大不能组合数和不能组合数的个数 思路:m和n的最大不能组合数为m*n-m-n,不能组合数的个数为(m-1)*(n-1)/2 推导: 先讨论最大不能组合数 因为gcd(m,n)= ...
- HDU 5858 Hard problem (数学推导)
Hard problem 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5858 Description cjj is fun with ...
随机推荐
- ng-options的使用
参考:官方文档.zhx1991 select 无默认选择一项 <select name="" id="" class="form-control ...
- linux环境下根据文件的某一列进行去重
momo@ubuntu:~/user/txt$ cat test.txt1 chen nihao2 chen hello3 li nimenhao4 he dajiahao5 li nimenhaom ...
- Html语言,使用<a>标签发送电子邮件
<a>标签有一个功能是可以链接Email地址,使用mailto能让访问者便捷向网站管理者发送电子邮件. 使用mailto 属性时请参考下表: 如果mailto里同时有多个参数,第一个参数必 ...
- C语言 printf 格式化输出函数
用 法: int printf(const char *format,[argument]); format 参数输出的格式,定义格式为: %[flags][width][.perc] [F|N|h| ...
- Django内置的用户认证
认证登陆 在进行用户登陆验证的时候,如果是自己写代码,就必须要先查询数据库,看用户输入的用户名是否存在于数据库中: 如果用户存在于数据库中,然后再验证用户输入的密码,这样一来就要自己编写大量的代码. ...
- Milk Patterns poj3261(后缀数组)
Milk Patterns Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 9274 Accepted: 4173 Cas ...
- .NET DateTime 源码学习
今天下载了微软.Net 源码,看了一下DateTime类,做下记录 DaysInMonth 这个方法是获取某年某月的天数,平时直接用觉得很简单,今天看到源码,发现设计的还是很好的 我想如果是我的话,封 ...
- php用PHPWord库生成word文档的例子
<?php require_once '../libs/PHPWord/PHPWord/IOFactory.php'; require_once '../../config.php'; $PHP ...
- webpack2使用ch4-向根目录index.html文件传参并使用参数 使用线上资源 压缩html
1 webpack.config.js const webpack = require('webpack'), htmlWebpackPlugin = require('html-webpack-pl ...
- 【转】 文档与笔记利器 reStructuredText 和 Sphinx
关于制作文档和笔记这种事,我已经纠结了很久,网上解决方案也一大推,我试过几样,ScrapBook 和 Zotero,编辑不太方便,同步麻烦.Google Note 过于格式简单,现在也不更新了,Goo ...