Hunan University of Technology Innovation Laboratory 2015 Freshman (i) 1003 (re-opened)

Source: Internet
Author: User

A Simple Problem iitime limit:3000/1000ms (java/other) Memory limit:65535/32768k (Java/other) total submission (s): 3 4 Accepted Submission (s): 20font:times New Roman | Verdana | Georgiafont Size:←→problem Description Hey, congratulations, see the game the simplest topic!
(Please don't do this question.)
for (i = 0;i <= n;i++) if (i%k==0) ans++;
Do this, or it will definitely time out, ikids in addition to long handsome, there are many girlfriends, but also never cheat! )

Waste (good) words do not say much, and listen to test instructions:

Give you a n, and K, your task is to output in 0~n How many numbers can be divided by K (if k in the 0~n range, nature also includes itself), is not very simple! That's fast and fast AC. Maybe someone is AC now!! Input inputs have more than one set of data, each set input two integers n and k

Where 1<=n,k<=10^9output outputs a digital ans, which represents the number of 0~n within a number divisible by K. Sample Input
1 12 1
Sample Output
23
authorikids  may wish to consider more points, [A, b] can be divisible by the number of  a<0 b<0      (-a)/k-(-B)/k consider whether or not divisible by a<0 b=0   & nbsp;  (-a)/k;   Plus 0 itself a<0 b>0      (b)/k+ (-a)/k plus 0 itself a=0 b>0      (b)/k   plus 0 itself a>0 b>0      (b)/k-(a)/k   consider whether a is divisible a=0 b=0      0 itself
#include <stdio.h>//#include <bits/stdc++.h> #include <string.h> #include <iostream> #include <math.h> #include <sstream> #include <set> #include <queue> #include <vector> #include <algorithm> #include <limits.h> #define INF 0x3fffffff#define Lson l,m,rt<<1#define Rson m+1,r,rt<    <1|1#define ll long longusing namespace Std;int main () {ll k,a,b;    LL ans=0;        while (cin>>b>>k) {LL ans=0;        a=0;            if (a<0&&b<0) {ans+= (-a)/k-(-B)/k;            if ((b)%k==0) {ans++;            }} else if (a<0&&b==0) {ans+= (-a)/k;        ans++;            } else if (a<0&&b>0) {ans+= (b)/k+ (-a)/k;        ans++;            } else if (a==0&&b>0) {ans+= (b)/k;        ans++; } else if (a>0&&b>0) {ans+ = (b)/k-(a)/k;            if (a%k==0) {ans++;        }} else if (a==0&&b==0) {ans++;    } cout<<ans<<endl; } return 0;}

  

Hunan University of Technology Innovation Laboratory 2015 Freshman (i) 1003 (re-opened)

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.