51nod 1082 与7无关的数
来源:互联网 发布:papi 知乎 编辑:程序博客网 时间:2024/06/05 06:58
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1082
题目:一个正整数,如果它能被7整除,或者它的十进制表示法中某个位数上的数字为7,则称其为与7相关的数。求所有小于等于N的与7无关的正整数的平方和。
例如:N = 8,<= 8与7无关的数包括:1 2 3 4 5 6 8,平方和为:155。
N的范围为1e6,所以用高精度打表。
妈妈问我为什么刷水题
#include <iostream>#include<bits/stdc++.h>#define N 1000002#define M 18using namespace std;int d[N][M];int ok(int t){ while(t) { if(t%10==7) return 0; t/=10; } return 1;}void init(){ memset(d[0],0,sizeof(d[0])); for(int i=1;i<N;i++) if(i%7&&ok(i)) { long long t=(long long)i*i; int jw=0; for(int j=0;j<M;j++) { d[i][j]=(d[i-1][j]+t%10+jw)%10; jw=(d[i-1][j]+t%10+jw)/10; t/=10; } } else { for(int j=0;j<M;j++) d[i][j]=d[i-1][j]; }}int main(){ init(); int T; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); int t=M-1; while(d[n][t]==0) t--; for(int i=t;i>=0;i--) cout<<d[n][i]; cout<<endl; }}
0 0
- 51nod 与7无关的数
- 51nod-1082 . 与7无关的数
- 51nod 1082 与7无关的数
- 51Nod-1082-与7无关的数
- 51nod 1082 与7无关的数
- 51nod-【1082 与7无关的数】
- 51nod 1082 与7无关的数
- 51Nod 1082 与7无关的数
- 51nod 1082 与7无关的数
- 51nod 1082 与7无关的数【打表】
- 51Nod 1082 与7无关的数
- 51 nod 1082 与7无关的数
- 51 nod 1082 与7无关的数
- 【51Nod】1082 与7无关的数
- 51Nod 1082 与7无关的数
- 51nod 1082 与7无关的数
- 51nod 1082 与7无关的数
- 51Nod 1082 与7无关的数 (打表)
- Instant Run requires 'Tools | Android | Enable ADB integration' to be enabled
- 5种调优Java NIO和NIO.2的方式
- 深入理解javascript原型和闭包(完结)
- 学习WCF之路3:在IIS中寄存服务
- 面试中常见链表问题5:删除链表中重复元素2
- 51nod 1082 与7无关的数
- Mysql 开启数据的远程访问权限
- Object.keys(obj)返回参数obj可被枚举的属性
- Leetcode题解(Python): 4.Median of Two Sorted Arrays (非递归)
- android库项目设置
- 盘点:2016中国百强地产CIO高峰论坛的8大看点
- ORA-12518: TNS: 监听程序无法分发客户机连接
- 使用ajax提交form表单
- ASP.NET MVC Razor 输出没有编码的HTML字符串