Codeforces Round #729 (Div. 2)

简介: 【6月更文挑战第4天】在这两个编程问题中,B. Plus and Multiply 要求判断通过加法和乘法操作数组是否能形成目标数 `n`。思路是形如 `x^a + yb = n` 的表达式,如果满足则能构造。C. Strange Function 关注的是找到最小正整数 `x` 使得 `x` 不是 `i` 的因子,计算这些值的和模 `10^9+7`。对于每个 `i`,偶数时 `f(i)` 是 3,奇数时是 2,利用因子与最大公约数计算周期性求和。

B. Plus and Multiply

http://codeforces.com/contest/1542/problem/B

http://codeforces.com/contest/1542/problem/B

题意:

一开始数组中只有一个$1$,你可以往数组里加入$数组中的数+b$或者加入$数组中的数*a$.问你$n$ 会出现在数组中吗?

思路:

我们随机匹配一下,最终的样式就是$x^a+yb=n$ 如果满足这种格式就一定能够构成

代码:

// Problem: B. Plus and Multiply
// Contest: Codeforces - Codeforces Round #729 (Div. 2)
// URL: http://codeforces.com/contest/1542/problem/B
// Memory Limit: 512 MB
// Time Limit: 3000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned long long ull;

#define x first
#define y second
#define sf scanf
#define pf printf
#define PI acos(-1)
#define inf 0x3f3f3f3f
#define lowbit(x) ((-x)&x)
#define mem(a,x) memset(a,x,sizeof(a))
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<=(b);++i)
#define repr(i,b,a) for(int i=int(b);i>=(a);--i)
#define debug(x) cout << #x << ": " << x << endl;

const int MOD = 998244353;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;
const int dx[] = {0, 1, -1, 0, 0};
const int dy[] = {0, 0, 0, 1, -1};
const int dz[] = {1, -1, 0, 0, 0, 0 };
int day[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

ll n,x,y;
priority_queue < ll> q;
map<ll,ll> mp;
ll qpow(ll a, ll b){
  ll ans=1;
  while(b){
    if(b&1) ans=ans*a;
    a=a*a;
    b>>=1;
  }
  return ans;
}
void solve()
{
  cin>>n>>x>>y;
  if(x==1){
    if((n-1)%y==0){
      puts("Yes");
    }else puts("No");
    return ;
  }
  for(ll i=0;;i++){
    ll num=qpow(x,i);
    ll yu=n-num;
    if(yu<0) break;
    if(yu%y==0) {
      puts("Yes");
      return ;
    }

  }
  puts("No");
}
int main()
{
    ll t = 1;
    scanf("%lld",&t);
    while(t--)
    {
        solve();
    }
    return 0;
}

C. Strange Function

http://codeforces.com/contest/1542/problem/C

题意:

记 $f(i)$ 为最小的正整数数 $x$ 满足 $x$ 不是 $i$ 的因子。

现给出正整数 $n$,请计算出 $\sum_{i=1}^n f(i)$ 模$ 10^9+7$ 的值。上述式子等价于 $f(1)+f(2)+\cdots+f(n)$。

本题含多组数据。令数据组数为 $t$,那么有 $1 \leq t \leq 10^4,1 \leq n \leq 10^{16}$

思路:

如果$i$ 是奇数那么$f(i)$ 一定是2

如果$i$ 是偶数那么$f(i)$ 最小是3

然后我们会发现 $f(i)=x $ 的话,那么$12\cdots*(x-1)$ 一定是$i$ 的因数 那么我们可以将$lcm(1\cdots(x-1))$ 作为x的周期.

这就是桥面的利用了这个周期,也就是题中给的性质最小一个不是他的因子,那么$1,2,\cdots,(i-1)$ 一定就是这个都是这个数的因子 那么直接就是他们的lcm就是周期即可.

代码:

// Problem: C. Strange Function
// Contest: Codeforces - Codeforces Round #729 (Div. 2)
// URL: http://codeforces.com/contest/1542/problem/C
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned long long ull;

#define x first
#define y second
#define sf scanf
#define pf printf
#define PI acos(-1)
#define inf 0x3f3f3f3f
#define lowbit(x) ((-x)&x)
#define mem(a,x) memset(a,x,sizeof(a))
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<=(b);++i)
#define repr(i,b,a) for(int i=int(b);i>=(a);--i)
#define debug(x) cout << #x << ": " << x << endl;

const int MOD = 998244353;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;
const int dx[] = {0, 1, -1, 0, 0};
const int dy[] = {0, 0, 0, 1, -1};
const int dz[] = {1, -1, 0, 0, 0, 0 };
int day[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

ll gcd(ll a,ll b){
  while(b){
    ll tmp=a%b;
    a=b;
    b=tmp;
  }
  return a;
}
ll a[50];
ll n;
void solve()
{
  cin>>n;
  ll ans=n*2%mod;
  ans=(ans+n/2)%mod;
  for(int i=4;a[i]<=n;i++){
    ans=(ans+n/a[i])%mod;
  }
  printf("%lld\n",ans);
}

int main()
{
  for(ll i=4,cnt=2;cnt<=1e16;i++){
    ll g=gcd(cnt,i-1);
    cnt = cnt/g*(i-1);
    a[i]=cnt;
  }
    ll t = 1;
    scanf("%lld",&t);
    while(t--)
    {
        solve();
    }
    return 0;
}
目录
相关文章
|
机器学习/深度学习 算法 计算机视觉
经典神经网络论文超详细解读(五)——ResNet(残差网络)学习笔记(翻译+精读+代码复现)
经典神经网络论文超详细解读(五)——ResNet(残差网络)学习笔记(翻译+精读+代码复现)
5227 1
经典神经网络论文超详细解读(五)——ResNet(残差网络)学习笔记(翻译+精读+代码复现)
|
11月前
|
存储 Java API
详细解析HashMap、TreeMap、LinkedHashMap等实现类,帮助您更好地理解和应用Java Map。
【10月更文挑战第19天】深入剖析Java Map:不仅是高效存储键值对的数据结构,更是展现设计艺术的典范。本文从基本概念、设计艺术和使用技巧三个方面,详细解析HashMap、TreeMap、LinkedHashMap等实现类,帮助您更好地理解和应用Java Map。
190 3
|
Java Serverless Go
Golang 开发函数计算问题之在 Golang 中避免 "concurrent map writes" 异常如何解决
Golang 开发函数计算问题之在 Golang 中避免 "concurrent map writes" 异常如何解决
196 0
|
Linux 存储 Windows
08. 【Linux教程】CentOS 目录介绍
08. 【Linux教程】CentOS 目录介绍
186 2
|
分布式计算 Hadoop 测试技术
Hadoop节点网络性能测试准备测试工具
【4月更文挑战第22天】选择合适的网络性能测试工具对于评估Hadoop集群的网络性能至关重要。这些工具可以帮助我们收集准确的数据,为优化集群配置和性能提供有力的支持。
182 1
|
JavaScript 前端开发
ESLint—— Failed to load config “standard“ to extend from
ESLint—— Failed to load config “standard“ to extend from
409 0
|
JavaScript 编译器 索引
TS进阶篇 | TS高级类型之字面量类型、联合类型、交叉类型(上)
TypeScript中除了基本类型之外,还定义了很多高级类型,高级类型包括字面量类型、联合类型、交叉类型、索引类型、映射类型、条件类型、this类型等。因为内容太多,所以这篇文章先来介绍前三个类型,其余类型会在高级类型的下篇介绍。
1295 0
EMQ
|
物联网 测试技术 网络性能优化
构建可靠的物联网系统:了解 MQTT 性能测试
性能测试对于确保物联网系统的稳定可靠至关重要。本文将介绍物联网系统性能测试的常见场景、挑战以及设计性能测试时需要考虑的因素。
EMQ
787 1
408计算机组成原理学习笔记——运算方法和运算电路(一)
408计算机组成原理学习笔记——运算方法和运算电路
547 1
408计算机组成原理学习笔记——运算方法和运算电路(一)