\(题意:定义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. B站插入外站链接地址(现已禁用)

    问题描述: B站中插入链接时,无法插入外站链接,提示[请输入正确的站内链接地址]: 日常文章编写中,经常需要插入外站链接跳转,以便于用户快速定位 分析: B站专栏文章编辑使用的富文本编辑器,应该是支持 ...

  2. Eclipse java项目转Maven项目

    1.右键项目->configure->选择maven->配置maven的pom.xml 2.在src/main下新建java文件,将原来src下的java文件夹拷贝至该目录下: 3. ...

  3. Eclipse 安装 阿里P3C编码规范插件

    操作:Help -> Install New Software -> add name: p3c location:https://p3c.alibaba.com/plugin/eclip ...

  4. jmeter操作数据库增删改查的注意事项

    一,场景 1.在jmeter造数据后,可通过数据库查询数据库是否新增数据,判断脚本执行是否成功. 2.有些数据新增不可重复,因此脚本执行后需要将新增的数据删除,才能再次执行脚本. 二.连接数据库 在通 ...

  5. js判断iOS还是Android

    /** * 运行设备引擎, 即iOS, Android还是H5 * 返回值注意大小写 * @return iOS, Android, H5 */ function engineType() { let ...

  6. 20241107,LeetCode 每日一题,使用 Go 计算两数相加

    思路 模拟加法:链表存储的是逆序数位,因此从头节点开始,逐位相加可以模拟正常的加法.每两个节点的值相加,并记录进位. 逐节点相加: 创建一个新的链表,用于存储结果,每次将两个链表对应节点的值加上进位值 ...

  7. kali安装charles

    00X01 kali安装charles wget -q -O - http://www.charlesproxy.com/packages/apt/PublicKey | sudo apt-key a ...

  8. Python3_python2打包exe文件

    最近要把绿盟报告导出脚本打包成一个exe,原本是一个py2的文件Vulreport.py,我做了如下步骤. 1.py2topy3 Python3 2to3.py -w Vulreport.py 2.p ...

  9. Java线程控制: sleep、yield、join深度解析

    结论先行 sleep:主动让出CPU但保持锁,适合控制执行节奏和优化CPU占用 yield:建议让出CPU但无强制力,适用场景有限且效果不稳定 join:通过等待机制实现线程顺序控制,底层基于wait ...

  10. 【深入解析AQS】从设计模式到ReentrantLock实现再到自定义锁

    深入解析AQS:设计模式.ReentrantLock实现与自定义锁开发 一.模板方法模式:AQS的架构基石 1.1 模式核心思想 模板方法模式通过固定算法骨架+可变实现细节的设计,实现了代码复用与扩展 ...