codeforces Round #641 div.2 A. Orac and Factorstime

本文探讨了数论中关于最小正除数的概念及其在迭代算法中的应用。通过具体实例,如求解特定操作下整数值的变化,展示了算法设计与数学理论的结合。深入解析了如何高效地计算和迭代,直至达到预定次数。
                     **A. Orac and Factorstime**
                        limit per test2 second
              smemory limit per test256 megabytes
                     input standard input
                     output standard output

Orac is studying number theory, and he is interested in the properties of divisors.For two positive integers aa and bb, aa is a divisor of bb if and only if there exists an integer cc, such that a⋅c=ba⋅c=b.For n≥2n≥2, we will denote as f(n)f(n) the smallest positive divisor of nn, except 11.For example, f(7)=7,f(10)=2,f(35)=5f(7)=7,f(10)=2,f(35)=5.For the fixed integer nn, Orac decided to add f(n)f(n) to nn.For example, if he had an integer n=5n=5, the new value of nn will be equal to 1010. And if he had an integer n=6n=6, nn will be changed to 88.Orac loved it so much, so he decided to repeat this operation several times.Now, for two positive integers nn and kk, Orac asked you to add f(n)f(n) to nn exactly kk times (note that nn will change after each operation, so f(n)f(n) may change too) and tell him the final value of nn.For example, if Orac gives you n=5n=5 and k=2k=2, at first you should add f(5)=5f(5)=5 to n=5n=5, so your new value of nn will be equal to n=10n=10, after that, you should add f(10)=2f(10)=2 to 1010, so your new (and the final!) value of nn will be equal to 1212.Orac may ask you these queries many times.InputThe first line of the input is a single integer t (1≤t≤100)t (1≤t≤100): the number of times that Orac will ask you.Each of the next tt lines contains two positive integers n,k (2≤n≤106,1≤k≤109)n,k (2≤n≤106,1≤k≤109), corresponding to a query by Orac.It is guaranteed that the total sum of nn is at most 106106.OutputPrint tt lines, the ii-th of them should contain the final value of nn in the ii-th query by Orac.
Example
input
5 1
8 2
3 4
output
12
12
NoteIn the first query, n=5n=5 and k=1k=1. The divisors of 55 are 11 and 55, the smallest one except 11 is 55. Therefore, the only operation adds f(5)=5f(5)=5 to 55, and the result is 1010.In the second query, n=8n=8 and k=2k=2. The divisors of 88 are 1,2,4,81,2,4,8, where the smallest one except 11 is 22, then after one operation 88turns into 8+(f(8)=2)=108+(f(8)=2)=10. The divisors of 1010 are 1,2,5,101,2,5,10, where the smallest one except 11 is 22, therefore the answer is 10+(f(10)=2)=1210+(f(10)=2)=12.In the third query, nn is changed as follows: 3→6→8→10→123→6→8→10→12.

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
 int t;
 long long int n,k;
 cin>>t;
 while(t--){
  cin>>n>>k;
   if(n%2==0) n=n+2*k;
   else if(n%2==1){
    for(int j=2;j<=n;j++)
     if(n%j==0) {n=n+j+2*k-2;break;} 
   } 
   cout<<n<<endl; 
  }
 return 0;
 } 
基于可靠性评估序贯蒙特卡洛模拟法的配电网可靠性评估研究(Matlab代码实现)内容概要:本文围绕“基于可靠性评估序贯蒙特卡洛模拟法的配电网可靠性评估研究”,介绍了利用Matlab代码实现配电网可靠性的仿真分析方法。重点采用序贯蒙特卡洛模拟法对配电网进行长时间段的状态抽样与统计,通过模拟系统元件的故障与修复过程,评估配电网的关键可靠性指标,如系统停电频率、停电持续时间、负荷点可靠性等。该方法能够有效处理复杂网络结构与设备时序特性,提升评估精度,适用于含分布式电源、电动汽车等新型负荷接入的现代配电网。文中提供了完整的Matlab实现代码与案例分析,便于复现和扩展应用。; 适合人群:具备电力系统基础知识和Matlab编程能力的高校研究生、科研人员及电力行业技术人员,尤其适合从事配电网规划、运行与可靠性分析相关工作的人员; 使用场景及目标:①掌握序贯蒙特卡洛模拟法在电力系统可靠性评估中的基本原理与实现流程;②学习如何通过Matlab构建配电网仿真模型并进行状态转移模拟;③应用于含新能源接入的复杂配电网可靠性定量评估与优化设计; 阅读建议:建议结合文中提供的Matlab代码逐段调试运行,理解状态抽样、故障判断、修复逻辑及指标统计的具体实现方式,同时可扩展至不同网络结构或加入更多不确定性因素进行深化研究。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值