1. 程式人生 > >hdu 1792 A New Change Problem(數論)

hdu 1792 A New Change Problem(數論)

A New Change Problem

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1236    Accepted Submission(s): 737


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 題意:求a和b的最大不能組合數和不能組合數的個數

思路:a和b的最大不能組合數為(a-1)*b-a,不能組合數的個數為(a-1)*(b-1)/2

程式碼:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
    int n,m;
    while(~scanf("%d %d",&m,&n))
    {
        printf("%d %d\n",(m-1)*n-m,(n-1)*(m-1)/2);
    }
    return 0;
}


相關推薦

hdu 1792 A New Change Problem數論

A New Change Problem Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1236    A

Hdu 1792 A New Change Problem 結論

  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

Hdu 1792 A New Change Problem 結論

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

HDU - 5974 A Simple Math Problem 數論 GCD

大於 case simple problem pan nbsp 因子 script not 題目描述: Given two positive integers a and b,find suitable X and Y to meet the conditions:

POJ 1740 A New Stone Game博弈題解

const 證明 one int ios scan space return i++ 題意:有n個石子堆,每一個都可以輪流做如下操作:選一個石堆,移除至少1個石子,然後可以把這堆石子隨便拿幾次,隨便放到任意的其他石子數不為0的石子堆,也可以不拿。不能操作敗。 思路:我們先來

Newcoder 110 A.最大乘積數論

Description 這題要你回答 T T T個詢問,給你一個正整數

HDU 2058:The sum problem數學

The sum problem Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

hdu 5572 An Easy Physics Problem數學

題意就是在一個二維空間中給一個起點終點 再給一個圓形彈性區域,起點給定一個方向,在這個空間中速度大小不變。 問起點能否在給定的方向下運動能夠到達終點。 這道題難點在於如何判斷碰到圓形區域後的速度方向, 不需要去算角度的 只要利用對稱點即可, 圓形上的接觸點

HDU 5402】Travelling Salesman Problem構造

被某題卡SB了,結果這題也沒讀好。。。以為每個格子可以有負數就當搜尋做了,怎麼想也搜不過去,後來發現每個格子是非負數,那麼肯定就是構造題。 題解如下: 首先如果nn為奇數或者mm為奇數,那麼顯然可以遍歷整個棋盤。 如果n,mn,m都為偶數,那麼講棋盤黑白染色,假設(

A new Graph Game HDU-3435

Problem Description An undirected graph is a graph in which the nodes are connected by undirected arcs. An undirected arc is an edge that has no a

hdu 4403 A very hard Aoshu problemdfs

【題目】 A very hard Aoshu problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/

A*B problemFFT

esp mat ble struct operator for fin void gist #include<iostream> #include<cstdio> #include<cstring> #include<cmath&

Problem A: 數組類I

支持 for http sin ret IT RR tor == Problem A: 數組類(I) Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 3295 Solved: 2418[Submit][Status][

洛谷P4907【CYH-01】小奔的國慶練習賽 :$A$換$B$ $problem$DFS,剪枝

技巧 show -h 可能 reg http 復雜度 tex \n 洛谷題目傳送門 順便提一下題意有一個地方不太清楚,就是如果輸出No還要輸出最少需要添加多少張牌才能滿足要求。蒟蒻考完以後發現四個點Too short on line 2。。。 比較需要技巧的搜索 既然是同一

【FZU - 1759】Super A^B mod C 數論,快速冪,快速乘,尤拉降冪,指數迴圈節,模板

題幹: Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=1000000000,1<=B<=10^1000000). Input There are mult

2018.11.07【POJ1740】A New Stone Game階梯博弈模仿策略

傳送門 解析: 首先,題目沒有說勝利判定方式啊,我去討論區看到勝利方式是拿走最後一顆石子。 這個博弈的主要策略是模仿。 每一方只需要保證對方有辦法可動的時候自己也有辦法可動就行了。 所以先手必敗的局面就是,有偶數堆石頭,並且每種大小的堆存在偶數個,因為只有這個時

hdu2058The sum problem解題報告---等差數列的和數論

                                        the sum

hdu 1757 A Simple Math Problem (矩陣快速冪

題目連結:hdu 1757 題意:見連結。 題解:直接構造矩陣,然後弄個矩陣快速冪就行了。                 程式碼如下: #include<cstdio

HDU 2058 - The sum problem等差數列

The sum problem Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 30916&n

HDU 1016 Prime Ring ProblemDFS

環狀的陣列,故注意判斷首圍相加是否為素數 一個用來存數,一個用來標記是否使用過該數 由n個數組成的環,就有n個素數對,這個是結束條件 #include<stdio.h> int n; int num[25]; int flag[25]; int p