URAL - 1243 - Divorce of the Seven Dwarfs (大数取模)

1243. Divorce of the Seven Dwarfs

Time limit: 1.0 second

Memory limit: 64 MB

After the Snow White with her bridegroom had left the house of the seven dwarfs, their peaceful and prosperous life has come to an end. Each dwarf blames others to be the reason of the Snow White‘s
leave. To stop everlasting quarrels, the dwarfs decided to part. According to an ancient law, their common possessions should be divided in the most fair way, which means that all the dwarfs should get equal parts. Everything that the dwarfs cannot divide
in a fair way they give to the Snow White. For example, after dividing 26 old boots, each dwarf got 3 old boots, and the Snow White got the remaining 5 old boots. Some of the numbers are very large, for example, the dwarfs have 123456123456 poppy seeds, so
it is not easy to calculate that the Snow White gets only one seed. To speed up the divorce, help the dwarfs to determine quickly the Snow White‘s part.

Input

The only line contains an integer N that represents the number of similar items that the dwarfs want to divide (1 ≤ N ≤ 1050).

Output

You should output the number of items that pass into the possession of the Snow White.

Sample

input output
123456123456
1

Problem Author: Stanislav Vasilyev

Problem Source: Ural State University Personal Programming Contest, March 1, 2003

Tags: none  (

hide tags for unsolved problems
)

开始刷刷URAL。。先水一个

AC代码:

#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <cctype>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define INF 0x7fffffff
using namespace std;

char s[105];

int main() {
	scanf("%s", s);
	int len = strlen(s);
	int ans = s[0] - '0';
	for(int i = 1; i < len; i ++) {
		ans = (ans * 10 + s[i] - '0') % 7;
	}
	printf("%d\n", ans);
	return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-06 06:03:49

URAL - 1243 - Divorce of the Seven Dwarfs (大数取模)的相关文章

ural 1243. Divorce of the Seven Dwarfs

1243. Divorce of the Seven Dwarfs Time limit: 1.0 secondMemory limit: 64 MB After the Snow White with her bridegroom had left the house of the seven dwarfs, their peaceful and prosperous life has come to an end. Each dwarf blames others to be the rea

快速幂+大数取模

快速幂+大数取模 快速幂,其实就是求(a^b)% p,(其中a,b,p都比较大在int范围内)这类问题. 首先要知道取余的公式:(a*b)%p=(a%p*b%p)%p. 那么幂不就是乘机的累积吗,由此给出代码: int fast(int a,int b,int p) {   long long a1=a,t=1; while(b>0) { if(b&1)          /如果幂b是奇数多乘一次,因为后边会除2变偶数,(7/2=3) t=(t%p)*(a1%p)%p; a1=(a1%p)*

csu 1556: Jerry&#39;s trouble(大数取模)

题意:求出1^m+2^m+...n^m 思路:直接套用模板 #include<cstdio> #include<iostream> #include<cstring> #include<cmath> #include<stdlib.h> #include<algorithm> #include<queue> #include<stack> #include<ctype.h> #define LL l

大数取模

//大数取模 #include "cmath" #include "iostream" #include "string.h" using namespace std; int mod(char str[],int num) { int number[100]; for(int i=0;i<strlen(str);i++) number[i]=str[i]-'0'; int remainder=0; for(int i=0;i<str

hdu2302(枚举,大数取模)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2303 题意:给出两个数k, l(4<= k <= 1e100, 2<=l<=1e6):其中k是两个素数的乘积,问k是否存在严格小于l的因子,若有,输出 BAD 该因子,反之输出GOOD: 思路: 先1e6内素数打表,再枚举一个因子,判断因子用大数取模: 代码: 1 #include <iostream> 2 #include <stdio.h> 3 #inclu

POJ 1426 Find The Multiple(大数取模)【DFS】||【BFS】

<题目链接> 题目大意: 给一个小于200的正整数n,问只有0和1组成的位数小于100的最小能被n整除的数是多少. 解题分析: 用DFS或者BFS沿着位数进行搜索,每一次搜索到下一位都有两种情况,0或者1,还要注意的是,大数取模的方法.但是我有一个疑问,这题位数最高为100,用dfs为什么不会超时?还是说只是此题数据太弱吗? BFS解法 #include<iostream> #include<cstdio> #include<queue> #include&

poj2635--The Embarrassed Cryptographer(数论篇1,大数取模)

The Embarrassed Cryptographer Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 12496   Accepted: 3330 Description The young and very promising cryptographer Odd Even has implemented the security module of a large system with thousands of

机试真题 大数取模运算

之前总结过,大数问题,取模就是取商取余数: #include<iostream> #include<stdlib.h> #include<string> using namespace std; string devide(int& r, string s, int n) { string ss = ""; for (int i = 0; i < s.size(); i++) { int temp = r*10 + int(s[i] -

hdu 1212 Big Number(大数取模)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1212 Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7083    Accepted Submission(s): 4884 Problem Description As we know, Big Number is