当前位置: 首页 > news >正文

Codeforces Round 1050 A. Sublime Sequence

A. Sublime Sequence

Farmer John has an integer xx. He creates a sequence of length nn by alternating integers xx and −x−x, starting with xx.

For example, if n=5n=5, the sequence looks like: x,−x,x,−x,xx,−x,x,−x,x.

He asks you to find the sum of all integers in the sequence.

Input

The first line contains an integer tt (1≤t≤100)  — the number of test cases.

The only line of input for each test case is two integers xx and nn (1≤x,n≤10).

Output

For each test case, output the sum of all integers in the sequence.

题意:n个x个数字,x数字为x,-x,x,-x等n个,计算这些x的和。

思路按照输入,然后整除2的为x,否则是-x,然后求和。

说明:可以一边输入一遍输出,也可以最后一起输出。最后输出需要一个vector数组或者int *数组

/*
4
1 4
2 5
3 6
4 7output
0
2
0
4
*/
#include <iostream>
using namespace std;int main()
{int t = 0;cin >> t;int x=0, n=0;int v1 = 0,sum=0;for (int i = 0; i < t; i++){cin >> x >> n;sum = 0;v1 = 0;for (int k = 0; k < n; k++){if (k%2==0){v1 = x;}else{v1 = x*(-1);}sum += v1;}cout << sum << endl;}return 0;
}

http://www.dtcms.com/a/423359.html

相关文章:

  • 欧拉路径与欧拉回路
  • 【C语言】计算两个整数二进制表示中不同位的个数
  • T5相对位置编码
  • 网站模板分类济阳做网站多少钱
  • 怎样做网站反链绵阳网站
  • Excel转PDF不分页
  • Serverless架构:无服务器计算的全面解析与实践指南
  • 记一次编译 debug 版本的 python 3.12.11 的过程
  • 需要上传视频的网站什么是html5网站
  • 深入Spring Boot的核心——配置管理(指南四)
  • 打工人日报#20250929
  • 论 AI Database
  • 免费建设网站公司哪家好如何做公司培训网站
  • 美工网站设计网站网页转小程序教程
  • 【JVM】基础篇(一)
  • 【关于虚拟机执行ip addr 命令不显示ip地址问题】
  • SpringBoot快速生成二维码
  • 张家港做网站费用gta5办公室网站正在建设
  • c#网站开发框架有没有免费的推广平台
  • XCVU13P-2FLGA2577I Xilinx AMD VirtexUltraScale+ FPGA
  • K8s优先级调度实战:创建高优先级类
  • 爱站网关键词长尾挖掘工具pc端网站转手机站怎么做
  • 微信小程序的获取当前位置--步骤
  • Mac OS远程执行Shell命令技巧
  • 传媒公司网站设计方案班级网站建设的参考文献
  • 使用python技术获取淘宝商品信息应注意规避哪些风险?
  • 早晨网站建设两当网站建设
  • 网站建设定制开发推广网站一年域名费用多少钱
  • 与主机安全息息相关的EDR
  • Next.js项目演示(从零创建Next.js项目)Next.js入门实战