Cigarettes (Nanyang oj94)

Source: Internet
Author: User
Tags integer numbers

Cigarettes time limit: theMs | Memory Limit:65535KB Difficulty:2
Describe

Tom has many cigarettes. We hypothesized that he has n cigarettes and smokes them

One by one keeping all the butts. Out of k > 1 butts He can roll a new cigarette.
Now,do know how many cigarettes can Tom have?

Input
First
input is a single Line,it's N and stands for there be n testdata.then there be n lines, each line contains T Wo integer numbers giving the values of N and K.
Output
for each line of input, output one integer number on a separate line giving the maximum number of cigarettes that Pe TER can has.
Sample input
34 310 3100 5
Sample output
514124
Source
[Rooot] Original
Uploaded by

Rooot

#include <stdio.h>int main () {int test,n,k,t,ans;scanf ("%d", &test), while (test--) {scanf ("%d%d", &n, &k); Ans=n;while (n>=k) {t=n/k;ans+=t;n=n-t*k+t;} printf ("%d\n", ans);} return 0;}

Cigarettes (Nanyang oj94)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.