\(题意:定义f(i)为不能整除i的最小整数,求\displaystyle\sum_{i=1}^n f(i)\)

思路:

逐步筛掉因子,首先考虑f(i)=2的,肯定是奇数,也就是除了剩下的n/2个偶数,奇数部分已经可以不考虑了,而且贡献是2。

然后剩下了Left = n/2个数,这些数已经是2的倍数了(剩下的那些偶数),再看这部分里面f(i)=3的,也就是不是3的倍数的,

有多少个呢?有Left-n/6个(除6是因为这部分同时满足是2和3的倍数),贡献为3,剩下的Left更新为n/6。

以此类推。

举个例子:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ===> ans = 0

一开始筛掉奇数,Left的部分为

2 4 6 8 10 12 14 16 18 ===> ans += 9 * 2 => 18

然后筛掉剩余部分不是是3的倍数的,只剩下:

6 12 18: ===> ans += 6 * 3 => 36

然后筛掉剩余部分不是4的倍数的(这个时候对应n/12,即是lcm(6,4)),只剩下:

12 ===> ans += 2 * 4 => 44

最后到筛吊剩余部分不是5的倍数的:

(空) ===> ans += 1 * 5 => 49

最后答案输出49

view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(long long i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} }; ll lcm(ll x, ll y)
{
return (x*y)/(gcd(x,y));
} int main()
{
int kase;
cin>>kase;
while(kase--)
{
ll n = read();
ll a[] = {2,5,7};
if(n<=2)
{
cout<<a[n-1]<<endl;
continue;
}
ll Left = n;
ll ans = 0;
ll cur = 1;
rep(i,2,55)
{
cur = lcm(cur,i);
ll toLeft = n/cur;
ans += (Left- toLeft)*i;
ans %= mod;
Left = toLeft;
if(Left<=0) break;
}
cout<<ans<<endl;
}
return 0;
}

Codeforces Round #729 (Div. 2) C. Strange Function的更多相关文章

  1. Codeforces Round #245 (Div. 1) 429D - Tricky Function 最近点对

    D. Tricky Function Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 codeforces.com/problemset/problem/42 ...

  2. Codeforces Round #277 (Div. 2) A. Calculating Function 水题

    A. Calculating Function Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/4 ...

  3. Codeforces Round #425 (Div. 2) C - Strange Radiation

    地址:http://codeforces.com/contest/832/problem/C 题目: C. Strange Radiation time limit per test 3 second ...

  4. codeforces水题100道 第十题 Codeforces Round #277 (Div. 2) A. Calculating Function (math)

    题目链接:www.codeforces.com/problemset/problem/486/A题意:求表达式f(n)的值.(f(n)的表述见题目)C++代码: #include <iostre ...

  5. Codeforces Round #277 (Div. 2)---A. Calculating Function (规律)

    Calculating Function time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. Codeforces Round #277 (Div. 2)A. Calculating Function 水

    A. Calculating Function   For a positive integer n let's define a function f: f(n) =  - 1 + 2 - 3 +  ...

  7. Codeforces Round #619 (Div. 2) Ayoub's function

    Ayoub thinks that he is a very smart person, so he created a function f(s)f(s) , where ss is a binar ...

  8. Codeforces Round #694 (Div. 1) - B. Strange Definition

    数论 Problem - B - Codeforces 题意 给定 \(n\;(1<=n<=3*10^5)\) 个数 \(a[i]\), \(1<=a[i]<=10^6\) 把 ...

  9. Codeforces Round #697 (Div. 3) G. Strange Beauty (DP,数学)

    题意:给你一组数,问你最少删去多少数,使得剩下的数,每个数都能整除数组中其它某个数或被数组中其它某个数整除. 题解:我们直接枚举所有因子,\(dp[i]\)表示\(i\)在数组中所含的最大因子数(当我 ...

  10. Codeforces Round #277 (Div. 2) 题解

    Codeforces Round #277 (Div. 2) A. Calculating Function time limit per test 1 second memory limit per ...

随机推荐

  1. 关于while循环与for循环

    首先看for循环 def test(): print('1') print('2') for i in range(3): test() 执行后的结果,按照下图所示,for循环就是把指定的函数重复执行 ...

  2. MySQL 的查询优化器如何选择执行计划?

    MySQL 的查询优化器负责决定如何执行 SQL 查询,它会根据多个因素选择最优的执行计划.查询优化器的目标是选择一个成本最低.性能最优的执行计划,以便高效地处理查询.执行计划的选择是基于 MySQL ...

  3. c#使用内存映射像处理内存一样去快速处理文件

    在 .NET Core 中,`System.IO.MemoryMappedFiles.MemoryMappedFile` 类提供了对内存映射文件的支持.通过将文件映射到内存,你可以在应用程序中直接访问 ...

  4. LM Studio本地使用

    一.概述 LM Studio 是一款桌面应用程序,用于在您的计算机本地开发和实验 LLM. 官方地址:https://lmstudio.ai 官方中文地址:https://lm-studio.cn 主 ...

  5. rider的xamarin环境安装

    自从用上rider后,vs就再也没有安装过了.最近要做apk开发,就安装xamarin环境,但是总是报错: Show Log->idea.log 发现下面错误: ERROR | Environm ...

  6. Java 多例设计模式

    /** * 多例设计模式:可以根据输入的参数不同返回不同的实例化对象 * 1.构造私有化 * 2.输入的参数不同 * 2017-09-11 * @author Junwei Zhu * */ clas ...

  7. 【经验】VScode 远程 SSH 连接 Ubuntu 或 TrueNas 出错,Could not establish connection

    用VScode常常会碰到以下情况,Could not establish connection. 先介绍一下VScode远程连接和终端SSH连接的区别:终端直接用SSH连接时,只需要开启SSH服务,并 ...

  8. Nacos源码—9.Nacos升级gRPC分析四

    大纲 10.gRPC客户端初始化分析 11.gRPC客户端的心跳机制(健康检查) 12.gRPC服务端如何处理客户端的建立连接请求 13.gRPC服务端如何映射各种请求与对应的Handler处理类 1 ...

  9. CI框架–头信息,构造器,视图

    今天继续学习CI框架的相关知识,分析下面语句,将匹配到的用户,Location跳转至相应界面,header()函数用来向客户端发送原始HTTP报头. `if ($this->user ['uid ...

  10. VS2019配置C++ boost库

    一.安装编译BOOST C++libary 1.安装Boost库 官网下载:https://www.boost.org/users/history/version_1_70_0.html 据说低于1. ...