C - Win or Freeze

CodeForces - 151C

题目内容:

    You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer q. During a move a player should write any integer number that is a non-trivial divisor of the last written number. Then he should run this number of circles around the hotel. Let us remind you that a number's divisor is called non-trivial if it is different from one and from the divided number itself.

    The first person who can't make a move wins as he continues to lie in his warm bed under three blankets while the other one keeps running. Determine which player wins considering that both players play optimally. If the first player wins, print any winning first move.
Input The first line contains the only integer q (1 ≤ q ≤ 1013). Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Output In the first line print the number of the winning player (1 or 2). If the first player wins then the second line should contain another integer — his first move (if the first player can't even make the first move, print 0). If there are multiple solutions, print any of them.
Examples
Input 6 Output 2 Input 30 Output 1
6 Input 1 Output 1
0 Note Number 6 has only two non-trivial divisors: 2 and 3. It is impossible to make a move after the numbers 2 and 3 are written, so both of them are winning, thus, number 6 is the losing number. A player can make a move and write number 6 after number 30; 6, as we know, is a losing number. Thus, this move will bring us the victory.

题意:给出一个数n,两个人轮流对其进行操作,把这个数换成他的非平凡因数(除了1和其本身的数)nn,如果那个人不能再对nn进行操作了,那他就赢了。在第一行中,打印获胜人的编号(1或2)。如果第一个玩家赢了,那么第二行应该包含另一个整数--他的第一个动作(如果第一个玩家连第一个动作都做不到,就打印0)。如果有多个解决方案,就打印其中任何一个。

题解:

当n为1或者质数时,找不到非平凡因数,所以第一个人一定赢;

当n为两个质数的乘积时,第二个人赢,因为第一个人要将该数换成它的非平凡数,而该数为质数,下一个人无法再进行操作。

其他情况时,第一个人只要把n换成是两个质数相乘而来的数就可以赢。

计算出n的所有质因数;

当n为8,那质因数为2,2,2;

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll n;
cin>>n;
if(n==1)
{
cout<<1<<"\n"<<0<<endl;
}
else{
ll q=n,ct=0;
vector<ll>s;
for(ll i=2;i*i<=n;i++)//找出所有质因数
{
while(n%i==0)
{
s.push_back(i);
n/=i;
++ct;
}
}
if(n!=1&&n!=q)s.push_back(n),++ct;//此时的n为质数,所以要记录下来
if(ct>2)cout<<1<<endl,printf("%I64d\n",s[0]*s[1]);
else if(ct==2)cout<<2<<endl;
else cout<<1<<endl<<0<<endl;
}
}

D - Quantity of Strings

CodeForces - 151D

题意:给出字符串的长度n,可使用的字符种类m,求使得任意k个子字符串都是回文的方案有多少个;

题解:当k为1或者k>n时,种类有m^n个;

当k=n时,有m^((k+)/2)种;

当k为奇数时有m*m种;

偶数时有m种;

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll show(ll m,ll n)
{
ll ct=1;
ll mod=1000000007;
for(ll i=1;i<=n;i++)
{
ct*=m;
ct%=mod;
}
return ct;
}
int main()
{
ll n,m,k;
scanf("%lld%lld%lld",&n,&m,&k);
if(k>n||k==1)printf("%lld\n",show(m,n));
else if(k==n)printf("%lld\n",show(m,(k+1)/2));
else if(k%2!=0)printf("%lld\n",m*m);
else printf("%lld\n",m); }

2021-5-15 vj补题的更多相关文章

  1. 2021.5.22 vj补题

    A - Marks CodeForces - 152A 题意:给出一个学生人数n,每个学生的m个学科成绩(成绩从1到9)没有空格排列给出.在每科中都有成绩最好的人或者并列,求出最好成绩的人数 思路:求 ...

  2. QFNU-ACM 2021.10.09 Rating补题

    A - A CodeForces - 478A 注意点: 和为0时要特判一下. 代码: #include<bits/stdc++.h> using namespace std; int m ...

  3. 【补题记录】ZJU-ICPC Summer Training 2020 部分补题记录

    补题地址:https://zjusummer.contest.codeforces.com/ Contents ZJU-ICPC Summer 2020 Contest 1 by Group A Pr ...

  4. 2020.12.20vj补题

    A - Insomnia cure 题意:一共s只龙,每隔k,l,m,n只龙就会受伤,问这s只龙有多少龙是受伤的 思路:看起来题目范围并不是很多,直接进行循环判断 代码: 1 #include< ...

  5. hdu5017:补题系列之西安网络赛1011

    补题系列之西安网络赛1011 题目大意:给定一个椭球: 求它到原点的最短距离. 思路: 对于一个椭球的标准方程 x^2/a^2 + y^2/b^2 +z^2/c^2=1 来说,它到原点的最短距离即为m ...

  6. 2017河工大校赛补题CGH and 赛后小结

    网页设计课上实在无聊,便开始补题,发现比赛时候僵着的东西突然相通了不少 首先,"追妹"这题,两个队友讨论半天,分好多种情况最后放弃(可是我连题目都没看啊),今天看了之后试试是不是直 ...

  7. 2018 HDU多校第四场赛后补题

    2018 HDU多校第四场赛后补题 自己学校出的毒瘤场..吃枣药丸 hdu中的题号是6332 - 6343. K. Expression in Memories 题意: 判断一个简化版的算术表达式是否 ...

  8. 2018 HDU多校第三场赛后补题

    2018 HDU多校第三场赛后补题 从易到难来写吧,其中题意有些直接摘了Claris的,数据范围是就不标了. 如果需要可以去hdu题库里找.题号是6319 - 6331. L. Visual Cube ...

  9. [数]补题ver.

    上次补题好像把两次训练混在一起了,总之先按时间顺序补完这一次|ू・ω・` ) HDU-6301 不会的东西不能逃避.jpg 红小豆非常讨厌构造题,因为非常不会,并且非常逃避学习这类题,因为总也搞不清楚 ...

随机推荐

  1. linux centos7 tail

    2021-08-30 # 不指定行数,默认显示 10 行 # 显示 /var/log/crond 后100行 taile -100 /var/log/crond # 动态显示 /var/log/cro ...

  2. zabbix 历史数据处理

    问题描述 zabbix server 平稳运行有一段时间了,但是最近问题却来了,今天早上收到zabbixserver磁盘空间不足的告警.通过查看之后发现是大部分数据是zabbix 库的的数据 在进一步 ...

  3. [考试总结]noip模拟43

    这个题目出的还是很偷懒.... 第一题...第二题...第三题...四.... 好吧... 这几次考得都有些问题,似乎可能是有些疲惫,脑袋也是转不太动,考完总觉得自己是能力的问题,但是改一分钟之后会发 ...

  4. 优化技术专题-线程间的高性能消息框架-深入浅出Disruptor的使用和原理

    前提概要 简单回顾 jdk 里的队列: 阻塞队列: ArrayBlockingQueue主要通过:数组(Object[])+ 计数器(count)+ ReetrantLock的Condition (n ...

  5. Mysql常用sql语句(6)- limit 限制查询结果的条数

    测试必备的Mysql常用sql语句系列 https://www.cnblogs.com/poloyy/category/1683347.html 前言 实际工作中,我们的数据表数据肯定都是万级别的,如 ...

  6. ubantu虚拟机搭建xl2tp服务

    在编译成功源码,安装完毕xl2tpd后,便可以配置xl2tpd服务.基本配置过程主要涉及两个配置文件:一个用来配置xl2tpd, 一个用来配置ppp协议.下面分别对这两个文件进行说明,最后添加xl2t ...

  7. 恶意软件开发——突破SESSION 0 隔离的远线程注入

    一.前言 在Windows XP,Windows Server 2003以及更早的版本中,第一个登录的用户以及Windows的所有服务都运行在Session 0上,这样的做法导致用户使用的应用程序可能 ...

  8. vue开发流程

    在安装node.js 测试安装  在cmd 下输入node   如查能正确输出命令提示符,表明安装好node 测试安装npm -v   如果能成功出现版本信息表示安装好npm 安装配置 G码云   或 ...

  9. Vue个人博客关于标题自动打字机效果Typewriter

    最近在写个人Blog 中间看过很多个人博客的开发 一大部分用的是Hexo框架或者vuePress框架 导入各种主题样式插件等等 但是看多了就会发现 很多博主的个人博客基本都很相似 并没有什么新东西呈现 ...

  10. 学习PHP中的高精度计时器HRTime扩展

    不知道大家还记得在学校的时候体育测试时老师带的秒表吗?当枪声想起时,我们开始跑步,这时秒表启动,当我们跑过终点后,老师会按下按扭记录我们的成绩,这就是一个典型的定时器的应用.今天我们要学习的内容其实就 ...