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

Problem Description
Now given two kinds of coins A and B,which
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.
 
Input
The input will consist of a series of pairs of integers A and B, separated by a space, one pair of integers per line.
 
Output
For each pair of input integers A and B you
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.
 
Sample Input
2 3 3 4
 
Sample Output
1 1 5 3
 
Author
lcy

/*************************************************************************
> 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规律推导)的更多相关文章

  1. 数学--数论--HDU1792A New Change Problem(GCD规律推导)

    A New Change Problem Problem Description Now given two kinds of coins A and B,which satisfy that GCD ...

  2. 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的想 ...

  3. HDU 2086 A1 = ? (找规律推导公式 + 水题)(Java版)

    Equations 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2086 ——每天在线,欢迎留言谈论. 题目大意: 有如下方程:Ai = (Ai-1 ...

  4. 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 ...

  5. 数学--数论--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 ...

  6. Codeforces Gym 100015A Another Rock-Paper-Scissors Problem 找规律

    Another Rock-Paper-Scissors Problem 题目连接: http://codeforces.com/gym/100015/attachments Description S ...

  7. FZU 2224 An exciting GCD problem(GCD种类预处理+树状数组维护)同hdu5869

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=2224 同hdu5869 //#pragma comment(linker, "/STACK:1024 ...

  8. hdu 1792 A New Change Problem(互质数之间最大不能组合数和不能组合数的个数)

    题意:求互质的m和n的最大不能组合数和不能组合数的个数 思路:m和n的最大不能组合数为m*n-m-n,不能组合数的个数为(m-1)*(n-1)/2 推导: 先讨论最大不能组合数 因为gcd(m,n)= ...

  9. HDU 5858 Hard problem (数学推导)

    Hard problem 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5858 Description cjj is fun with ...

随机推荐

  1. Unity GameObject Class

    GameObject  Note : gameObject 指的是当前挂着的对象. class in UnityEngine / Inherits from:Object     Descriptio ...

  2. xml解析案例

    步骤:Channel是java bean类 public static List<Channel> parsexml(InputStream inputStream) {//注意服务器种是 ...

  3. mac pycharm 里table键设置为4个空格键

    Operation flow: File--Default Settings editor--code style--python

  4. TCP/IP(三)数据链路层~2

    一.局域网 1.1.局域网和以太网的区别和联系 局域网:前面已经介绍了,其实就是学校里面.各个大的公司里,自己组件的一个小型网络,这种就属于局域网. 以太网:以太网(Ethernet)指的是由Xero ...

  5. CentOSv6.8 修改防火墙配置、修改SSH端口

    查看防火墙目前使用状况: service iptables status 修改防火墙配置: vi /etc/sysconfig/iptables 重启防火墙,让刚才修改的配置生效: service i ...

  6. 1297. Palindrome ural1297(后缀数组)

    1297. Palindrome Time limit: 1.0 secondMemory limit: 64 MB The “U.S. Robots” HQ has just received a ...

  7. http://codeforces.com/contest/535/problem/C

    C. Tavas and Karafs time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  8. iOS开发注意事项(一)

    1.OC的消息机制与C++等的函数(方法)有很大的不同,OC在运行时所执行的代码由运行环境来决定,而C++等则由编译器决定.如果调用的函数是多态的,C++在运行时要按照虚方法表来查出到底执行哪个函数, ...

  9. thrift例子:python客户端/java服务端

    java服务端的代码请看上文. 1.说明: 这两篇文章其实解决的问题是,当使用python去访问大数据线上集群的时候,遇到两个问题: 1)python-hadoop和python-hive相关包链接不 ...

  10. 从template到DOM(Vue.js源码角度看内部运行机制)

    写在前面 这篇文章算是对最近写的一系列Vue.js源码的文章(https://github.com/answershuto/learnVue)的总结吧,在阅读源码的过程中也确实受益匪浅,希望自己的这些 ...