【2017 Multi-University Training Contest

Link:http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1005&cid=765

Description

问你a%b的结果有多少种.
b未知,可以为任意数字.

Solution

b=a+1,a,a-1,a-2….
分别对应了a%b==a,0,1,2,…
且当b = a/2时,a%b会出现重复..
找一下a为奇数和偶数的两种情况.
发现规律就是(a-1)/2 + 2;

NumberOf WA

0

Reviw


Code

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x+1)
#define oi(x) printf("%d",x)
#define ol(x) printf("%lld",x)
#define oc putchar(' ')
#define os(x) printf(x)
#define all(x) x.begin(),x.end()
#define Open() freopen("F:\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0)

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 110;

int main(){
    //Open();
    //Close();
    int T;
    ri(T);
    while (T--){
        int a;
        ri(a);
        oi((a-1)/2 + 2);puts("");
    }
    return 0;
}
原文地址:https://www.cnblogs.com/AWCXV/p/7626117.html