CF 10C Digital Root
来源:互联网 发布:php mongodb扩展 编辑:程序博客网 时间:2024/06/06 04:33
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102123#problem/C
题目大意:判断1~n中有多少数满足a*b!=c,但是数位和(mod 9)满足a*b=c。
题目分析:分别判断,先算出总数在减去a*b=c的,a*b=c的不能用n^2算法,所以用统计每个作为a,b的数x有n/c个,累和即可。
由于n较小,若n为10^9则统计a*b=c需用sqrt n的算法。
AC代码:
#include<stdio.h>#include<cmath>#include<iostream>#include<algorithm>#include<cstring>using namespace std;int main(){long long n,i,j,m,ans;t=0; ans=0;scanf("%I64d",&n);m=int(sqrt(n));for (i=1;i<=m;i++){ans=ans-n/i*2;}ans=ans+m*m;for (i=1;i<=n%9;i++) a[i]++;for (i=0;i<=8;i++) a[i]=a[i]+n/9;for (i=0;i<=8;i++)for (j=0;j<=8;j++)ans=ans+a[i]*a[j]*a[i*j%9];printf("%I64d\n",ans);}
0 0
- CF 10C Digital Root
- CodeForces 10C. Digital Root
- codeforces 10C C. Digital Root(数论)
- Codeforces 10C Digital Root 规律题
- #10 C. Digital Root (数论)
- CodeForces 10 C.Digital Root(数论)
- Digital Root
- digital root
- digital root
- Digital Root 算法
- Digital Root----code forces
- HDU 4351 - Digital root
- hdu4351 Digital root
- [SGU]118. Digital Root
- sgu 118 Digital Root
- Digital Root的问题
- Vasya and Digital Root
- POJ 1519 digital root
- LeetCode 160 Intersection of Two Linked Lists(链表相交)(Linked List)(*)
- POJ 1837 二维背包 天平平衡问题
- SQL之模糊查询
- Codeforces Round #340 (Div. 2):A. Elephant
- <LeetCode OJ> 144 / 145 / 94 Binary Tree (Pre & In & Post) order Traversal
- CF 10C Digital Root
- 3450: Tyvj1952 Easy 概率与期望 DP
- 面试题
- Leetcode Array题型总结
- 猴子分桃
- 读《钝感力》有感
- Codeforces Round #340 (Div. 2):B. Chocolate
- NCrawler 开源爬虫框架学习
- 1000个赞的《快乐码农》