NC200444. QAQ
描述
输入描述
一行三个整数k, x, y
1 <= k <= 1051 <= x <= y <=109
输出描述
一个整数,表示答案
示例1
输入:
1 2 7
输出:
6
Java 解法, 执行用时: 43ms, 内存消耗: 10584K, 提交时间: 2022-08-10 14:01:50
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int k=sc.nextInt(); int x=sc.nextInt(); int y=sc.nextInt(); int len,count=0; len=y-x+1; for (int i = 1,t=0; i <=k ; i+=2,t++) { if ((t&1)==1) { if ((x&1)==1) { count+=len/2; } else { count+=(len+1)/2; } } else count+=len; count%=1000000007; } System.out.println(count); } }
C++14(g++5.4) 解法, 执行用时: 13ms, 内存消耗: 540K, 提交时间: 2019-12-17 20:14:53
#include<bits/stdc++.h> using namespace std; #define int long long typedef long long LL; const int MAXN = 1005; const int MOD = 1e9+7; //x%4==1 --> all 1 //x%4==3 --> 01 signed main(){ //freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin); int k,x,y; cin>>k>>x>>y; int res=0,t1=k/4,t2=k%4; int a=t1+(t2>=1),b=t1+(t2>=3); if(x&1) res = (a*(y-x+1)+b*((y-x+1)/2))%MOD; else res = (a*(y-x+1)+b*((y-x)/2+1))%MOD; cout<<res<<endl; return 0; }
C++11(clang++ 3.9) 解法, 执行用时: 5ms, 内存消耗: 504K, 提交时间: 2019-12-19 00:13:07
#include <bits/stdc++.h> using namespace std; #define ll long long const ll mod = 1e9+7; int main() { ll k, x, y; cin >> k >> x >> y; k = k - k / 2; ll a = k / 2; cout << (a * (y / 2 - (x - 1) / 2) + (k - a) * (y - x + 1)) % mod << "\n"; return 0; }